PHP uses get to transfer the encoding and conversion of Chinese Characters

Source: Internet
Author: User
Tags php source code

Introduction: This is a detailed page for PHP to transfer Chinese characters using get. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 325735 'rolling = 'no'>

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, as shown below:Code:

 
$ STR = rawurlencode (iconv ("GBK", "UTF-8", "who I am"); echo "<br>". $ 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;

More articles about "php uses get to transfer Chinese character encoding and conversion"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/325735.html pageno: 13.

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.