Home > headlines > body text

PHP string function (1): length calculation

无忌哥哥
Release: 2018-06-28 10:36:53
Original
2014 people have browsed it

* 1.strlen($str)

* 2.mb_strlen($str, $encoding)

$siteName = 'php中文网';
Copy after login

//Get the internal character encoding set

$encoding =   mb_internal_encoding();
echo &#39;内部字符编码集: &#39;,$encoding,&#39;<br>&#39;;
Copy after login

/ /1.strlen($str): Get the string length represented by bytes

//In utf8 mode, a Chinese character is represented by three bytes

echo strlen($siteName),&#39;<br>&#39;;
Copy after login

//2.mb_strlen ($str, $encoding): Get the length represented by the number of characters

echo mb_strlen($siteName, $encoding),&#39;<br>&#39;;
Copy after login

//Omit the second parameter, the system default character encoding set will be used, which is currently utf-8

echo mb_strlen($siteName),&#39;<br>&#39;;  //返回值不变
Copy after login
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