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 solution is not very good, it can solve the problem and the instance generation of the problem.
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 solution is not very good, it can solve the problem. The instance code of the problem is as follows:
- $ Arr = array
- (
- 'Name' => 'chia ',
- 'Age' => 20
- );
- $ Jsonencode = json_encode ($ arr );
- Echo $ jsonencode;
- ?>
The results are as follows: {"Name": null, "Age": 20}. the Chinese language is empty. why? 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.