GB2312 VS UTF-8 Solution _php Techniques for PHP character encoding problems

Source: Internet
Author: User
Look at the code:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> New Document </title>
<meta name= "Author" content= ""/>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
<link rel= "stylesheet" type= "Text/css" href= ""/>

<body>
<?php
$string 1 = "I am a phper";
$string 2 = "This website is a cloud-dwelling community";
Print_r (Str_split ($string 1));
echo "<br/>";
Print_r (Str_split ($string 2,4));
?>
</body>

The test results are what I expected-- Chinese garbled

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

Because English is not garbled, only Chinese garbled, first thought of the coding problem, then suddenly remembered to UTF-8 code is UTF-8 need 3 bytes, dead Horse when live horse medicine!

So Print_r (Str_split ($string 2,4)), 4 of this sentence, was replaced by 6, so--see the results

Also, you can try to change the encoded charset UTF-8 to GB2312, because Unicode encoding requires 2 bytes, so Gb2312 coding can save 1/3 more space than UTF-8, but if you want to be compatible with traditional Chinese, Korean, Other languages in Japanese need to use UTF-8.

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.