PHP character encoding problem GB2312VSUTF-8_PHP tutorial

Source: Internet
Author: User
GB2312VSUTF-8 of PHP character encoding problems. Today, I wrote some code according to the book. the code intends to use the str_split () function to split the string into an array. it is easy to say in English, but Chinese is separated (two Chinese characters and one array unit) today, I wrote some code according to the book. the code is intended to use the str_split () function to split the string into arrays. it is easy to say in English, but Chinese is separated (two Chinese characters and one array unit) there is a problem --

Check the code:

> Http://www.w3.org/TR/html4/loose.dtd ">

New Document

$ String1 = "I am a phper ";

$ String2 = "this book is a blue ocean strategy ";

Print_r (str_split ($ string1 ));

Echo"
";

Print_r (str_split ($ string2, 4 ));

?>

  

I expected the test results to be output-Chinese garbled characters

Why? Why? Why? Why? What is garbled code? What is garbled? Explain to me what is % & garbled!

Because English without garbled characters, only Chinese garbled characters, first of all think of the encoding problem, so suddenly think of the UTF-8 encoding is UTF-8 needs 3 bytes, dead horse as a doctor!

Therefore, print_r (str_split ($ string2, 4); 4 in this sentence is changed to 6, and the result is almost -- view the result

Similarly, you can also try to change the UTF-8 of charset encoding to GB2312, because Unicode encoding requires 2 bytes, so the Gb2312 encoding can save 1/3 of the space than the UTF-8, but if you want to be compatible with other languages of traditional Chinese, Korean, and Japanese, you need to use UTF-8.

By the way, I found the first dynamic Music and shared it with me:

-Its OK?

-Its OK!

When the merge () function is split into arrays, the English language is good, but the Chinese language is separated (two Chinese characters and one array unit...

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.