PHP judge input does not exceed the length range of the MySQL varchar field _php tips

Source: Internet
Author: User
But if the Utf-8 code, a Chinese character is 3 characters long, such as String $str= "Hello!!";

If you use the Strlen function to determine that the length is 11, just over the length of the varchar, but actually it is not so, if you directly to the phpMyAdmin to execute the INSERT statement, this string can be inserted!

For a database, its length is 5, so how do we use PHP to get that length? Use the Iconv_strlen () function!

Echo Iconv_strlen ($str, ' utf-8′);

Note that the second argument is the current character set, so that the results you get from a different character set are calculated based on a character's length!

The above statement, will output 5, how would you judge it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.