Chinese often encounters problems intentionally or unintentionally in PHP development. Today we will take a look at the solution to json_encode Chinese garbled characters. Although the method is not very good, it can solve the problem as long as
The code is as follows
代码如下 |
复制代码 |
$arr = array
(
'Name'=>'希亚',
'Age'=>20
);
$jsonencode = json_encode($arr);
echo $jsonencode;
?>
|
|
Copy code
|
$arr = array
(
'Name'=>'Shia',
'Age'=>20
代码如下 |
复制代码 |
$array = array
(
'title'=>iconv('gb2312','utf-8','这里是中文标题'),
'body'=>'abcd...'
);
echo json_encode($array);
?>
|
);
$jsonencode = json_encode($arr);
echo $jsonencode;
?>
|
The results are as follows
{"Name":null,"Age":20}
Chinese characters are empty, what is the reason? Read on below
Let’s test utf-8
The code is as follows
|
Copy code
$array = array
(
'title'=>iconv('gb2312','utf-8','This is the Chinese title'),
'body'=>'abcd...'
);
echo json_encode($array);
?>
Results
{"title":"u8fd9u91ccu662fu4e2du6587u6807u9898","body":"abcd..."}
It’s not what we thought, then we use the php urlencode() function to process the following. Before json_encode, use urlencode() to process all the contents of all arrays
This way there will be no problem with Chinese.
http://www.bkjia.com/PHPjc/632254.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632254.htmlTechArticleChinese often encounters problems intentionally or unintentionally in PHP development. Today we will take a look at the solution to json_encode Chinese garbled characters. There is a way, although the method is not very good, but it can solve the problem with just code...
|
|