The mb_substr function is an upgraded version of the substr function. mb_substr supports Chinese interception and will not cause garbled characters. Let me introduce the basic knowledge of mb_substr.
Example
The code is as follows
|
Copy code
|
||||||||
$str = ‘This way my string will not be garbled^_^’; echo “mb_substr:” . mb_substr($str, 0, 7, ‘utf-8′);//Result: In this way, my words echo “”; echo “mb_strcut:” . mb_strcut($str, 0, 6, ‘utf-8′); //Result: like this
In actual use, it needs to be used in conjunction with mb_strlen. The usage of mb_strlen is similar to strlen, except that there is an additional encoding parameter: mb_strlen("I am the character whose length is to be calculated", "gbk"); the result is 11. Detailed usage examples:
{ Make sure you have the php_mbstring.dll file under Windows/system32. If not, copy it from your Php installation directory extensions into Windows/system32. |