The PHP mb_substr () function intercepts the Chinese string application example,
The substr () function is used to intercept strings, but there is a problem with Chinese characters, and mb_substr () and Mb_strcut functions can be similar to substr (), except that at the end of the function you add more than one parameter to set the encoding of the string. Using these two functions requires the Php_mbstring.dll to be opened in the php.ini.
<?php header ("content-type:text/html; Charset=utf-8 "); $string =" Hello, I'm good everyone "; Echo strlen ($string). '
'; Echo mb_substr ($string, 0,4, ' utf-8 '). ' ...
'; Echo mb_strcut ($string, 0,4, ' utf-8 '). ' ...';? >
Results of the output:
21st
Hello I'm good ...
You...
As can be seen from the above example, Mb_substr is to divide characters by word, while mb_strcut divides characters by bytes, but does not produce a half-character phenomenon.
http://www.bkjia.com/PHPjc/852375.html www.bkjia.com true http://www.bkjia.com/PHPjc/852375.html techarticle The php mb_substr () function intercepts the Chinese string application example, and the substr () function is used to intercept the string, but there is a problem for Chinese characters, and the Mb_substr () and mb_strcut are the two functions ...