Gunah Gaar Gunah Gaar - 2 months ago 6x
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)));