mb_strwidth
Returns the width of the string
Function name: mb_strwidth()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7
Function description: The mb_strwidth() function returns the width of the specified string (in characters) and uses multibyte character set encoding.
usage:
mb_strwidth ( string $str [, string $encoding = mb_internal_encoding() ] ) : int
parameter:
Return value:
Example:
$str = "你好,世界!"; $width = mb_strwidth($str, 'UTF-8'); echo "字符串的宽度为:$width"; // 输出:字符串的宽度为:7
In the example above, we use the mb_strwidth() function to calculate the width of a string containing Chinese characters. Since the width of Chinese characters is 2 characters, the result is 7.