PHP learning note _ encoding (json_encode is not displayed in Chinese)

Source: Internet
Author: User

Find a solution on the Internet: Copy codeThe Code is as follows: <? Php
/* Process json_encode Chinese garbled characters */
$ Data = array ('game' => 'Ice-fire status', 'name' => 'thorn spirit ', 'country' => 'Ice-frome status ', 'level' => 45 );
Echo json_encode ($ data );
Echo "<br> ";
$ NewData = array ();
Foreach ($ data as $ key => $ value ){
$ NewData [$ key] = urlencode ($ value );
}
Echo urldecode (json_encode ($ newData ));
?>

Later, I consulted someone and I could use base64 encoding. However, base64 encoding cannot be placed in URLs. Baidu explained this as follows:

The standard Base64 is not suitable for direct transmission in the URL, because the URL encoder will convert the "/" and "+" characters in the standard Base64 into the form of "% XX, these "%" signs need to be converted when they are stored in the database, because "%" has been used as a wildcard in ansi SQL.

However, my data is sent through POST, not in the HTTP head, but in the message-body, so it is not affected.

Json_encode can only accept UTF-8 data

Urlencode base64_encode can only accept parameters of the string type, so the entire array cannot be encoded.

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.