Php judges that the input does not exceed the length range of the mysql varchar field. However, in UTF-8 encoding, a Chinese character occupies three characters, for example, the string $ str "Hello !!"; If you use the strlen function to determine that the length is 11, which is more than the value of varch. However, if a Chinese character occupies three characters in UTF-8 encoding, for example, string $ str = "Hello !! ";
If you use the strlen function to judge that the length is 11, which is more than the length of varchar, but it is actually not like this. if you directly execute the insert statement in phpmyadmin, this string can be inserted!
For a database, the length is 5. how can we use PHP to get the length? Use the iconv_strlen () function!
Echo iconv_strlen ($ str, 'utf-8 ′);
Note that the second parameter is the current character set. Therefore, based on different character sets, the result is calculated based on the length of one character!
The above statement will output 5. how do you know?
Bytes !!"; If you use the strlen function, the length is 11, which exceeds the value of varch...