PHP character encoding problem: GB2312 VS UTF-8 solution_PHP tutorial

WBOY
Release: 2016-07-21 15:27:58
Original
1013 people have browsed it

Look at the code:

Copy the code The code is as follows:





New Document







$string1 = "i am a phper";
$string2 = "This website is a home for scripts";
print_r(str_split($string1));
echo "
";
print_r(str_split( $string2,4));
?>



The test results came out as I expected——Chinese Garbled characters

PHP character encoding problem: GB2312 VS UTF-8 solution_PHP tutorial

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

PHP character encoding problem: GB2312 VS UTF-8 solution_PHP tutorial

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323663.htmlTechArticleLook at the code: Copy the code as follows: !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/ /EN" "http://www.w3.org/TR/html4/loose.dtd" html head meta http-equiv="Content-Type"...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!