PHP mb_substr () function intercept 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 are the two functions, so let's introduce their specific usage.
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.
Header ("content-type:text/html; Charset=utf-8 ");
$string = "Hello i 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/852829.html www.bkjia.com true http://www.bkjia.com/PHPjc/852829.html techarticle The php mb_substr () function intercepts the Chinese string application example substr () function is used to intercept strings, but for Chinese characters there is a problem, and mb_substr () and mb_strcut are two functions ...