I storing unicode tamil character in database I am trying to retrieve it using php an display in browser. I am putting it to in array and get it in json. I a am getting the following output
{
"product_id":"29",
"download_id":"ebbe8e1e1f4649bb8a51468828100d91",
"order_key":"wc_order_5492e914ee249",
"post_title":"\u0ba4\u0bae\u0bbf\u0bb4\u0bcd \u0bae\u0bc2\u0bb2\u0bbf\u0b95\u0bc8\u0b95\u0bb3\u0bcd \u0b89\u0ba3\u0bb5\u0bc1\u0b95\u0bc1\u0b95\u0bb3\u0bcd",
"status":"true"
}
I am using the following code,
$sql = "SELECT wdp.product_id, wdp.download_id, wdp.order_key, wp.post_title
FROM product_permissions wdp, posts wp
WHERE wdp.user_email = 'testemail@gmail.com'
AND wdp.product_id = wp.ID";
$result = mysql_set_charset( 'utf8' );
$result = mysql_query($sql);
$int_num_field = mysql_num_fields($result);
while($row = mysql_fetch_array($result)){
$arr_col = array();
for($i=0;$i<$int_num_field;$i++){
echo $row[$i];
$arr_col[mysql_field_name($result,$i)] = $row[$i];
}
$arr_col['status']= 'true';
array_push($json,$arr_col);
}
array_push($person,$json);
$main = array('products'=>$json);
echo json_encode($main);
try this echo json_encode($main,JSON_UNESCAPED_UNICODE);
In php 5.4+, php's json_encode does have the JSON_UNESCAPED_UNICODE option for plain output. On older php versions, you can roll out your own JSON encoder that does not encode non-ASCII characters, or use Pear's JSON encoder.
EDIT
or you can try this function
function jsonRemoveUnicodeSequences($struct) {
return preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", json_encode($struct));
}