1. Chinese interception: mb_substr()
mb_substr( $str, $start, $length, $encoding)
$str, the string that needs to be truncated
$start, the starting point of truncation, the starting point is 0
$length, the number of words to be intercepted
$encoding, web page encoding, such as utf-8, GB2312, GBK
Example:
Copy code The code is as follows:
$str='Script Home: http://www .jb51.net';
echo mb_substr($str,0,4,'utf-8');//Intercept the first 5 characters, assuming that the encoding of the php file where this code is located is utf-8
? >
The results show: Script Home
2. Get the Chinese length: mb_strlen() mb_strlen( $str, $ encoding )
$str, the string to calculate the length
$encoding, web page encoding, such as utf-8, GB2312, GBK
Example:
Copy code The code is as follows:
$str='Script Home: http://www.jb51.net';
echo mb_strlen($str,'utf-8');//Assume that the encoding of the php file where this code is located is utf-8
?>
The result shows: 24
http://www.bkjia.com/PHPjc/324581.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324581.htmlTechArticle1. Chinese interception: mb_substr() mb_substr( $str, $start, $length, $encoding ) $str , the string that needs to be truncated $start, the starting point of truncation, the starting point is 0 $length, the number of words to be intercepted...