Home > Backend Development > PHP Tutorial > PHP计算中文字符串长度 、截取对应中文字符串

PHP计算中文字符串长度 、截取对应中文字符串

WBOY
Release: 2016-06-23 13:46:38
Original
992 people have browsed it

PHP计算字符串长度     及其   截取对应中文字符串



计算字符长度:

$gouWu = '美日汇http://www.hnzyxok.com/';

echo mb_strlen($gouWu,'utf-8') ;    //输出的结果是26,里面包含了中文字母符号的计算,在该函数加上 UTF-8行  ,否则算出来的就是32(一个中文对应的长度是3)



对应截取中文:

 echo mb_substr($gouWu,0,10,'utf-8').;     //从$gouWu变量中对应取10个字符,记得加后面那个参数哦


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