Newbie's question about mb_strlen. I don't quite understand the returned values of these three calls .. PHPcode & lt ;? Phpechomb_strlen (& quot; my name & quot;). & quot; & lt; br/& gt; & quot; // Questions about mb_strlen for beginners of 12echomb_str.
I don't quite understand the returned values of these three calls ..
PHP code
"; // 12 echo mb_strlen (" My Name "," UTF-8 ")."
"; // 4 echo mb_strlen (" My Name "," GBK ") // 6?>
The code is saved in l. php, and the file is encoded as utf8
About the second encoding parameter of mb_strlen. Written in the PHP manual:
"The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used ."
I want to know which encoding the internal character encoding refers to and where it is configured.
Also, the return value of this function is written in this way.
"Returns the number of characters in string str having character encoding. A multi-byte character is counted as 1 ."
Multi-byte characters are calculated by 1.
The first call will return 12, and the second call will return 6 .. I don't quite understand. I hope to explain it to you. thank you!
------ Solution --------------------
Discussion
Well, there is another small problem. If you want to use functions in other DLL files in PHP, do you want to copy the DLL to system32, and then add it to php. ini?
Can Code Like extension = php_fdf.dll be used?
------ Solution --------------------
PHP code
Echo mb_strlen ("My Name ")."
"; // 12 echo mb_strlen (" My Name "," UTF-8 ")."
"; // 4 echo mb_strlen (" My Name "," GBK ") // 6
------ Solution --------------------
First your file encoding must be UTF-8, and your mb_internal_encoding is similar to the ISO-8859-1
Then we need to know that one utf8 Chinese character is 3 bytes, and gb is 2 bytes. mb_strlen counts the multi-byte word as 1, so we will get
Echo mb_strlen ("My Name ")."
"; // Unspecified encoding, calculated by default ISO-8859-1, a utf8 Chinese character is 3
Echo mb_strlen ("My Name", "UTF-8 ")."
"; // Given the correct encoding, one Chinese character is 1
Echo mb_strlen ("My Name", "GBK") // given the error code, GBK calculates 2 for a Chinese character, but your file is utf8, 4*3 = 12 bytes/2 = 6 gbk characters
?>