Phpjson_encode Chinese garbled solution _ PHP Tutorial

Source: Internet
Author: User
Phpjson_encode Chinese garbled solution. Chinese often encounters problems intentionally or unintentionally in php Development. let's take a look at the json_encode Chinese garbled solution today, although the method is not very good, but the problem can be solved only when the Chinese code is encountered intentionally or unintentionally in php Development. let's take a look at the json_encode Chinese garbled solution today. Although the solution is not good, it can only solve the problem.
The code is as follows:

$ Arr = array
(
'Name' => 'chia ',
'Age' => 20
);

$ Jsonencode = json_encode ($ arr );
Echo $ jsonencode;
?>

The result is as follows:

{"Name": null, "Age": 20}

Chinese is blank. why? let's take a look at it.
Let's test UTF-8

The code is as follows:

$ Array = array
(
'Title' => iconv ('gb2312', 'utf-8', 'Here is the Chinese title '),
'Body' => 'abcd ...'
);

Echo json_encode ($ array );
?>

Result
{"Title": "u8fd9u91ccu662fu4e2du6587u6807u9898", "body": "abcd ..."}

This is not what we want, so we use the php urlencode () function to process the following. before json_encode, we use urlencode () to process all the content in the array.

In this way, there is no problem with Chinese.

Pipeline development often encounters problems intentionally or unintentionally. let's take a look at the json_encode Chinese garbled solution today. Although the solution is not very good, it can solve the problem only by code...

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.