mb_strlen
Get the string length
Function name: mb_strlen()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7
Function description: The mb_strlen() function returns the length of the specified string in characters. The mb_strlen() function is multibyte-safe.
Usage: mb_strlen(string $str, string|null $encoding = null): int
parameter:
Return value: Returns the length of the specified string in characters.
Example:
$str = "Hello, 你好!"; $length = mb_strlen($str, "UTF-8"); echo "字符串的长度为:" . $length;
Output: The length of the string is: 10
Description: In the above example, we used the mb_strlen() function to calculate the length of the string $str. Since the string contains Chinese characters, we specify the character encoding as "UTF-8". The length returned by the function is 10 because "Hello, hello!" has 10 characters in total.