Gunah Gaar Gunah Gaar - 7 months ago 35
JSON Question

PHP JSON encode issue and retrieval issue

I usually do this to encode simple strings to be obtained via an AJAX request.

$str = '<img src="someinage.png" />';
echo json_encode(array('status'=>'OK',$str));

The output:

{"status":"OK","html":"<img src="someinage.png" />"}

See the double quotes, how can I avoid this issue?


Use the html_entity_decode function for the $str.

$str = '<img src="someinage.png" />';
echo json_encode(array('status'=>'OK',html_entity_decode($str)));