PHP uses GET to transfer the encoding of Chinese characters

Source: Internet
Author: User
How does PHP use GET to transfer the encoding of Chinese characters? When we use GET to transmit Chinese character encoding, different browsers may have different problems. Therefore, we should first transcode Chinese characters and convert them to unicode for transmission. the following code: $ strrawurlencode (iconv (GBK, UTF-8, who I am); echo & lt; br & gt ;. $ str ;? In this way, "who am I" will use PHP to transmit the encoding and conversion of Chinese characters using GET.

? When we use GET to transmit Chinese character encoding, different browsers may have different problems. Therefore, we should first transcode Chinese characters and convert them to unicode for transmission. the following code:

$ Str = rawurlencode (iconv ("GBK", "UTF-8", "who I am"); echo"
". $ Str;

? In this way, "who am I" will be converted to a code similar to: % E6 % 88% E6 % 91% AF % E8 % B0 % 81 and transmitted on the browser address;

When receiving this parameter, you need to reverse convert the encoding in two steps:

1. define the encoding format of the page:

This is the first step. it requires the browser to display the encoding when reading this page. Therefore, we should add the header encoding definition on our page:

Header ("Content-Type: text/html; charset = gbk ");

What encoding is;

II. received data:

When the GET method is used for Chinese character transmission, it will be parsed to unicode encoding by the browser. Therefore, we should first convert it to UTF-8 encoding:

??????

$_articleName = rawurldecode($_articleName) ;

?????? Rawurldecode is about to convert the encoding format similar to: % E6 % 88% E6 % 91% AF % E8 % B0 % 81 to UTF-8;

Then use iconv to convert the encoding:

$_articleName = iconv("UTF-8", "GBK", "$_articleName"); 

?

In this way, the gbk encoding is displayed normally;

Gb2312 is the same, just change gbk to gb2312;

?

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.