This article mainly describes how to use PHP to determine the input does not exceed the length of the MySQL field of the varchar range, has a certain reference value, now share to everyone, the need for friends can refer to
varchar Type field, if you set the length to 10, then both Chinese characters and English can save 10.
However, if the Utf-8 encoding, a Chinese character is 3 characters in length, such as the string $str= "Hello Ah!!";
If you use the Strlen function to judge that the length is 11, just over the length of the varchar, but in fact it is not so, if directly into the phpMyAdmin inside the INSERT statement, this string can be inserted!
For a database, its length is 5, then how do we use PHP to get this length? Use the Iconv_strlen () function!
Echo Iconv_strlen ($str, ' utf-8′);
Note that the second argument is the current character set, so that depending on the character set, the result you get is calculated from one character per length!
The above statement, will output 5, how, you will judge it?
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!