What is the principle of the mb_detect_encoding function in PHP?

Source: Internet
Author: User
PHP mb_detect_encoding can be based on the input string to determine exactly what kind of code it belongs to, how this judgment is done, utf-8 and ASC width are different, and the former is still long, how it determines whether the extra byte is the next word or the last byte of the word

Reply content:

PHP mb_detect_encoding can be based on the input string to determine exactly what kind of code it belongs to, how this judgment is done, utf-8 and ASC width are different, and the former is still long, how it determines whether the extra byte is the next word or the last byte of the word

It's utf-8 ascii better to say how to judge ascii and not to differentiate.ascii
asciiThe maximum is 127 , when judged, as long as this byte is greater than 127, that 7f is, it can be assumed that this byte is a multibyte encoding. Whether it is GBK or is UTF-8 compatible ascii .
1. utf-8 the first byte of each word has a total number of bytes for that word. All data types that are variable length are basically implemented, such as the fact that the database varchar has more bytes saved, so it will not be misread.
2. GBK is equal-width double-byte, as long as this byte is not a ascii character, it and the next read together is OK
3. As to how to guess utf-8 and gbk , I do not understand. Guess should be through some algorithms, to match the coding law or Code table bar, about this can refer to: http://blog.csdn.net/ecjtuync/article/details/1774429

  • Related Article

    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.