PHP Learning Random Notes _ Encoding (json_encode Chinese not shown) _php tutorial

Source: Internet
Author: User
Find a workaround on the Web:
Copy CodeThe code is as follows:
/* Handling Json_encode Chinese garbled */
$data = Array (' Game ' = ' ice Fire country ', ' name ' = ' thorn spirit ', ' country ' + ' frost State ', ' level ' = 45);
echo Json_encode ($data);
echo "
";
$newData = Array ();
foreach ($data as $key = = $value) {
$newData [$key] = UrlEncode ($value);
}
Echo UrlDecode (Json_encode ($newData));
?>

Later consulted others, but also can use Base64 code, but base64 code can not put in the URL, Baidu is such explanation:

The standard Base64 is not intended to be transmitted directly in the URL because the URL encoder will change the "/" and "+" characters in the standard Base64 into forms such as "%XX", and these "%" numbers need to be converted when they are deposited into the database because ANSI SQL has used the "%" number as a wildcard character.

But my data is sent via post, not in the head of HTTP, but in Message-body, so it's not affected.

Json_encode can only accept data in utf-8 format

UrlEncode Base64_encode can only accept arguments of type string, so the entire array cannot be encoded.

http://www.bkjia.com/PHPjc/324558.html www.bkjia.com true http://www.bkjia.com/PHPjc/324558.html techarticle find a solution on the Web: Copy code as follows: PHP/* Processing Json_encode Chinese garbled */$data = array (' Game ' = ' ice Fire country ', ' name ' = ' thorn spirit ', ' country ' = ' ice '). .

  • 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.