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):