Home > Backend Development > PHP Tutorial > PHP string length function_PHP tutorial

PHP string length function_PHP tutorial

WBOY
Release: 2016-07-20 11:01:45
Original
1154 people have browsed it

PHP string length function, there are two functions to test the string length in PHP, one is strlen, the other is mb_strlen. The former one is supported by default, and the latter one needs to open a plug-in. Let's introduce the difference between the two functions. Application method. ​

php tutorial string length function, there are two functions to test the string length in php, one is strlen, the other is mb_strlen. The former one is supported by default, and the latter one needs to open a plug-in, as follows Let’s introduce the differences and application methods of the two functions.

php strlen() function
Definition and Usage
The strlen() function returns the length of a string.

Grammar
strlen(string) parameter description
string required. Specifies the string to check.

echo strlen("www.bkjia.com!"); //13
echo strlen("Chinese!");//6 The value obtained by strlen is twice the number of Chinese characters
?>

Try to copy php_mbstring.dll to the %windows% directory

$str = 'Everyone who knows PHP knows that strlen and mb_strlen are functions to find the length of a string';
echo strlen($str)'.
'.mb_strlen($str,'utf-8');
?>

Run the above code and the return value is as follows:
66
34

Everyone who knows PHP knows that strlen and mb_strlen are functions to find the length of a string, but for some beginners, if they don’t read the manual, they may not be clear about the difference.
Let’s look at this piece of code first (prerequisite: character encoding is utf-8):


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445409.htmlTechArticlephp string length function, there are two functions to test the string length in php, one is strlen, the other It is mb_strlen. The former one is supported by default, and the latter one needs to open a plug-in. Next I...
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