SUBSTR () function can be used to split the text, but the text to be divided if the inclusion of Chinese characters tend to encounter problems, you can use MB_SUBSTR ()/mb_strcut This function, Mb_substr ()/mb_strcut usage and substr () similar, Just in Mb_substr ()/mb_strcut to add more than one parameter to set the string encoding, but the general server did not open Php_mbstring.dll, need to php.ini in the Php_mbstring.dll to open.
As an example:
<?phpecho mb_substr (' This way my string will not have garbled ^_^ ', 0, 7, ' utf-8′); >
Output: so that my word
<?phpecho mb_strcut (' This way my string will not have garbled ^_^ ', 0, 7, ' utf-8′); >
Output: this
As can be seen from the above example, MB_SUBSTR is the word to divide the characters, and mb_strcut is to divide the characters by Byte, but will not produce a half-character phenomenon ...
The above paragraph is a excerpt from the network, the results are tested by myself.
Personal Understanding:
The Mb_substr () function represents one unit for English or Chinese characters.
The Mb_strcut () function pairs Chinese characters in 3 units, and English is 1 units.
For example:
<?php$str = "Such ABCD Comes", echo "Mb_substr:". Mb_substr ($str, 0, 5, ' utf-8′); echo "<br>", echo "Mb_strcut:". mb_ Strcut ($str, 0, 8, ' utf-8′);? >
The output results are as follows:
MB_SUBSTR: So abcmb_strcut: so AB
Report:
The difference between strlen and Mb_strlen:
<?php $str = "Chinese a character 1 characters"; echo strlen ($STR); echo "<br/>"; Echo Mb_strlen ($str, ' utf8′);?>
Output Result:
14 6
The above is PHP intercept Chinese string length mb_substr (), mb_strcut () function content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!