submithandler PHP Chinese processing Chinese string interception mb_substr and get the number of Chinese string words

WBOY
Release: 2016-07-29 08:47:11
Original
1203 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, to Number of words intercepted
$encoding, web page encoding, such as utf-8, GB2312, GBK
Example:

Copy code The code is as follows:


$str='This site: 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: This website


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='This site: 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

The above introduces submithandler PHP Chinese processing, Chinese string interception mb_substr and obtaining the number of Chinese string characters, including the content of submithandler. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!