Gunah Gaar Gunah Gaar - 1 year ago 82
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?

Answer Source

Use the html_entity_decode function for the $str.

$str = '<img src="someinage.png" />';
echo json_encode(array('status'=>'OK',html_entity_decode($str)));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download