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