PHP Intercept String If it is English that very good, directly with substr on the line, generally will not appear garbled. Chinese is a bit of a hassle.
Here are two ways to solve the problem:
(a) directly using the Multi-Byte function library mb_substr (); the function is OK, the instance code is as follows
"; ? >
This method is simple, fast, safe, beautiful, seductive ... Anyway what good word can describe it, but, unfortunately my GoDaddy host does not support, so have to find another way out
(b) Custom intercept Chinese string function, basically is modeled mb_substr write a function, directly call it, the following is the code I found, actually very simple
=161)//is Chinese {$start _index+=2; } else//is English {$start _index+=1; }} $chr _index= $start _index; Intercept for ($i =0; $i < $len; $i + +) {$asc =ord ($str _input{$chr _index}); if ($asc >=161) {$return _str{$i}=chr ($ASC); $return _str{$i +1}=chr (ord ($str _input{$chr _index+1)); $len +=1; End condition plus 1 $i + +; Position offset plus 1 $chr _index+=2; Continue } else {$return _str{$i}=chr ($ASC); $CHR _index+=1; }} return Trim ($return _str); }//en