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