First, Chinese interception: Mb_substr ()
Mb_substr ($str, $start, $length, $encoding)
$str, a string that needs to be truncated
$start, starting at 0 at the beginning of the truncation
$length, the number of words to intercept
$encoding, page encoding, such as UTF-8,GB2312,GBK
Instance:
Copy Code code as follows:
<?php
$str = ' cloud-dwelling community: http://www.jb51.net ';
Echo mb_substr ($str, 0,4, ' utf-8 ');/intercept the first 5 words, assuming that the code in the PHP file is encoded as Utf-8
?>
The results show that cloud-dwelling communities
Second, get Chinese length: Mb_strlen ()
Mb_strlen ($str, $encoding)
$str, the string to compute the length
$encoding, page encoding, such as UTF-8,GB2312,GBK
Instance:
Copy Code code as follows:
<?php
$str = ' cloud-dwelling community: http://www.jb51.net ';
Echo Mb_strlen ($str, ' utf-8 ');//Assume that the PHP file that this code resides in is encoded as Utf-8
?>
Results showed: 24