Utf-8-How does PHP work uniformly using UTF8 encoding?

Source: Internet
Author: User
The PHP language has not resolved the UTF8 (Unicode) problem, which is confusing in many encodings.
Write a truncate function and use a special mbstring to handle it.

Under existing conditions (php5+ ~ php7), how can we achieve uniform use of UTF8 encoding?

python3+, Golang, etc. all built-in support and use Unicode encoding ...

Reply content:

The PHP language has not resolved the UTF8 (Unicode) problem, which is confusing in many encodings.
Write a truncate function and use a special mbstring to handle it.

Under existing conditions (php5+ ~ php7), how can we achieve uniform use of UTF8 encoding?

python3+, Golang, etc. all built-in support and use Unicode encoding ...

In strict terms, PHP does not have the concept of a string, and the string in PHP is actually the concept of a byte array.

The unit of the string (string) is the character (character), and the unit of the byte array (byte[]) is in bytes (byte)

How one or more bytes make up a character is encoded by the so-called encoding (such as single-to-one and supports only 128-character ASCII)

For PHP, he is very simple to deal with only bytes, not processing characters, but also can be said to support arbitrary encoding, the only thing to be aware of is that the function of string is not used for string processing, but rather for the byte array (binary data), You need to use the MB library when it comes to string processing that really means something.

And if the main problem is that the data source coding different scenarios, then no matter how the language processing can only do encoding conversion, MB or iconv can help you

transcoding AH.

Transcoding is required for those that require uniform encoding.

Get encoding Type: mb_detect_string ()

Code conversion: Iconv (), see the PHP Manual for details, about international characters, multibyte character processing ...

  • 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.