Home >Backend Development >PHP Tutorial >php json_encode Chinese garbled solution_PHP tutorial

php json_encode Chinese garbled solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:55:09821browse

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 results are as follows
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;

?>

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

Chinese characters are empty, what is the reason? Read on below
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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn