How to get substring of unicode characters from mysql using php -


the unicode characters stored in mysql database in format

یہاں تو 

there no unicode characters in database html , english characters mixed up.

the problem want part of string database field 'post_body' have used following sql query

"select substring(post_body,1,120) pst_body mytable"; 

this string gives me 120 characters accurately. problem if there unicode symbols in database ی equal 1 unicode character, requirement not fulfill in way. there function can give me specified number of characters regardless of unicode character or english character, mean if there unicode data should count ی 1 character .

i not think, there option in mysql, can fetch data mysql take action in php.

function getsubstring($string, $number){      $keywords = preg_split("/([&])+/", htmlentities($string));     $finalarray = array();     unset($keywords[0]);      for($index = 1;$index <= $number;$index++){         $finalarray[] = $keywords[$index];     }     return str_replace('amp;', '&', implode('', $finalarray)); }   //$string = &#1740;&#1729;&#1575;&#1722; &#1578;&#1608;  //$number = 10;// number of character fetch  echo getsubstring($string,10); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -