In PHP, strlen and Mb_strlen is a function of string length PHP built-in string length function strlen Unable to correctly handle the Chinese string, it gets only the number of bytes of the string. For the Chinese encoding of GB2312, the value of strlen is twice times the number of Chinese characters, and for UTF-8 encoded Chinese, is 3 times times (in UTF-8 encoding, a Chinese character accounted for 3 bytes). Using Mb_strlen function can solve this problem well. The usage of Mb_strlen is similar to strlen, except that it has a second optional parameter for specifying character encoding. For example get UTF-8 string str length, can be used with Mbstrlen (str length, can be used with Mbstrlen (str, ' UTF-8 '). If you omit the second argument, the internal encoding of PHP is used. The internal code can be obtained through the mb_internal_encoding () function. It is important to note that Mb_strlen is not a PHP core function and needs to be sure that the Php_mbstring.dll is loaded in the php.ini before use, that is, to ensure that the "Extension=php_mbstring.dll" line is present and not commented out. Otherwise, there is an issue with undefined functions.
The role and Difference of Php--strlen () and Mb_strlen