Ali Ali - 9 months ago 31
JSON Question

How to remove escaping special characters from json_encode output

I have some urls in my database and I want to print them as JSON using php. How can I get the desired format, without escaping backslashes, in my JSON object?

//business to get data
...
//print json data
echo json_encode($customer,JSON_UNESCAPED_UNICODE);


enter image description here

Answer Source

Just remove the \ you can do that using str_replace().

str_replace("\\", "", json_encode($customer,JSON_UNESCAPED_UNICODE));

Here is a link to the str_replace() function in the php manual: http://php.net/manual/en/function.str-replace.php

Edit: I forgot to escape the backslash. It works now!