The solution of the Chinese garbled problem in PHP json_encode _php tips

Source: Internet
Author: User
The following PHP code resolves the following issues:
1.json_encode UTF8 code in Chinese after the string is not readable
The problem of Chinese garbled 2.json_encode in multi-series group
The 3.json_encode array contains a newline error problem
Problems in 4.json_encode array with Chinese keys
Copy Code code as follows:

function _encode ($arr)
{
$na = Array ();
foreach ($arr as $k => $value) {
$na [_urlencode ($k)] = _urlencode ($value);
}
Return Addcslashes (UrlDecode (Json_encode ($na)), "\\r\\n");
}

function _urlencode ($elem)
{
if (Is_array ($elem)) {
foreach ($elem as $k => $v) {
$na [_urlencode ($k)] = _urlencode ($v);
}
return $na;
}
Return UrlEncode ($elem);
}

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.