user889030 user889030 - 2 months ago 16
JSON Question

php json_encode bug patch

i have data in text file which i load to array rows wise , but recently i have noticed that when "µ" come in data then json_encode retrun blank response ,and when i remove "µ" from data then json_encode function work

i have php version 5.5.3

$dat = array("0"=>"hello","1"=>"world");
echo json_encode($dat); // work

$data = array("0"=>"hello","1"=>"180.00 10µH");
echo json_encode($data); // blank response ..

i searched for json_enocde function on github php page , but its all in C ,

so any idea how to patch this function


Use like the following code:

$data = array("0"=>"hello","1"=>"180.00 10µH");
$data = array_map("utf8_encode", $data);
echo json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);