Home > Backend Development > PHP Tutorial > PHP Chinese processing Chinese string interception (mb_substr) and obtaining the number of Chinese string words_PHP tutorial

PHP Chinese processing Chinese string interception (mb_substr) and obtaining the number of Chinese string words_PHP tutorial

WBOY
Release: 2016-07-21 15:23:05
Original
881 people have browsed it

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

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template