The substr() function can be used to split text, but if the text to be split includes Chinese characters, you will often encounter problems. In this case, you can use the mb_substr()/mb_strcut function. The usage of mb_substr()/mb_strcut is the same as that of substr( ) is similar, except that one more parameter needs to be added at the end of mb_substr()/mb_strcut to set the encoding of the string. However, most servers do not open php_mbstring.dll. You need to open php_mbstring.dll in php.ini.
For example:
Output: This way my words
Output: This way
From above As can be seen from the example, mb_substr splits characters by words, while mb_strcut splits characters by bytes, but neither will produce half a character...
The above paragraph is excerpted from the Internet , the results are all obtained through my own testing.
Personal understanding:
mb_substr() function represents a unit for English or Chinese characters.
mb_strcut() function is 3 units for Chinese characters and 1 unit for English characters.
For example:
”; echo “mb_strcut:”.mb_strcut($str, 0, 8, ‘utf-8′); ?>
The output result is as follows:
mb_substr: 这样abc mb_strcut: 这样ab
Attachment:
The difference between strlen and mb_strlen:
”; echo mb_strlen($str,’UTF8′); ?>
Output result:
14 6
The above is the content of mb_substr() and mb_strcut() functions that PHP uses to intercept the length of Chinese strings. For more related content, please pay attention to PHP Chinese Net (m.sbmmt.com)!