The mb_substr function is an upgraded version of the substr function. mb_substr supports Chinese truncation without garbled characters. The following describes the basic knowledge of mb_substr. for example, the code is as follows :? Php $ s... the mb_substr function is an upgraded version of the substr function. mb_substr supports Chinese truncation without garbled characters. Next, let's introduce the basic knowledge of mb_substr.
For example, the code is as follows:
"; Echo" mb_strcut: ". mb_strcut ($ str, 0, 6, 'utf-8'); // The result is as follows:
From the above example, we can see that mb_substr is used to split characters by words, while mb_strcut is used to split characters by bytes, but it does not produce half a character.
In actual use, it needs to be used with mb_strlen. the usage of mb_strlen is similar to that of strlen, but an encoding parameter is added: mb_strlen ("I am a character to be calculated for length ", "gbk"); the result is 11.
For example, if there are more than 20 strings to be intercepted, the code is as follows:
if(mb_strlen($str, "gbk") >20) { $str = mb_substr($str, 0, 20, "gbk"); }
Note: Make sure that you have the php_mbstring.dll file in Windows/system32. if not, just export it to Windows/system32 from the extensions directory of your Php installation directory.
2. in the windows directory, find php. ini and open the editor. search for mbstring. dll. find; extension = php_mbstring.dll and remove the number; so that the mb_substr function will take effect.
Address:
Reprinted at will, but please attach the article address :-)