Wednesday 25 December 2019

json encode chinese character php

json encode chinese character php

-------json_encode() in PHP returns Chinese characters in escaped-------

Many time you were not able to create php json_encode from special characters which generate the  null. I have a code by which you can create a valid json in php 


//****************start encodeing***********/
$data  = array(
array('Sr No'=> 1,'name' => "删除一个连续数组值的方式产生的非连续数组"),
array('Sr No'=> 2,'name' => "删除一个连续数组值的方式产生的非连续数组"),
array('Sr No'=> 3,'name' => "删除一个连续数组值的方式产生的非连续数组")
);


foreach ($data as $key => $value) {
$data[$key]['name'] = mb_convert_encoding($value['name'], "UTF-8", "UTF-8");
}
echo json_encode($data);

///*************end ********************//

using  mb_convert_encoding($string, "UTF-8", "UTF-8");
function you can easily create a valid jSon 

// ************output is given below ***********//
php json_encode special characters null solved

Method 2:  Change collation to utf8mb4_unicode_ci In mysql DB of your column.

Thanks for sharing your time. I believe that you issue has been resolved Please Give a comment to support my efforts. Thanks