Home >Backend Development >PHP Tutorial >PHP character encoding problem: GB2312 VS UTF-8_PHP tutorial
I wrote a piece of code based on the book today. The purpose of the code is to use the str_split() function to split a string into an array. It is easy to speak in English, but there is a problem when splitting Chinese (two Chinese and one array unit)——
Look at the code:
>http://www.w3.org/TR/html4/loose.dtd ">
$string1 = "i am a phper";
$string2 = "This book is about blue ocean strategy";
print_r(str_split($string1));
echo "print_r(str_split($string2,4));
?>
The test result came out as I expected - Chinese garbled characters
Why? Why? Why? Why? What is garbled code? What is garbled code? Explain to me, what is the garbled code of %&!
Because there are no garbled characters in English but only Chinese garbled characters, I first thought about the encoding problem, and then suddenly remembered that the encoding of UTF-8 is that UTF-8 requires 3 bytes. Let’s treat it like a dead horse!
So print_r(str_split($string2,4)); the 4 in this sentence was replaced by 6, so - look at the result
Similarly, you can also try changing the UTF-8 of the encoded charset to GB2312. Because Unicode encoding requires 2 bytes, Gb2312 encoding can save 1/3 of the space than UTF-8. But if you want to be compatible with other languages such as Traditional Chinese, Korean, and Japanese, you need to use UTF-8.
By the way, I discovered the first dynamic music, and I want to share it with you:
—Its Ok?
—Its OK!