Ashok Gujjar Ashok Gujjar - 7 months ago 9
SQL Question

how to reverse back of mysql_escape_string function in php?

I am storing

[{
"id": "a34da9b020ec86dc5a7832620082ed5d",
"type": "img",
"name": "1458561170282.jpg",
"mime_type": "image/jpg",
"path": "http://images.website.com/boxdata/asset22756/images/1458561170282.jpg?r=160321075523",
"thumb": "http://images.website.com/boxdata/asset22756/images/thumb__1458561170282.jpg?r=160321075523",
"short_link": "http://website.com/img1084109"
}]


in a MySQL database using
mysql_escape_string
function.

When I retrieve the data I have the following output:

[\n {\n \"short_link\" : \"http:\\\\/\\\\/website.com\\\\/img1085805\",\n \"id\" : \"ca96c55e1aa76fbca17ee08cad7e5a15\",\n \"thumb\" : \"http:\\\\/\\\\/images.website.com\\\\/boxdata\\\\/asset22114\\\\/images\\\\/thumb__chat_files_41.jpg?r=160421015318\",\n \"type\" : \"img\",\n \"path\" : \"http:\\\\/\\\\/images.website.com\\\\/boxdata\\\\/asset22114\\\\/images\\\\/chat_files_41.jpg?r=160421015318\",\n \"name\" : \"chat_files_41.jpg\",\n \"mime_type\" : \"image\\\\/jpg\"\n }\n]


How can I convert my data back in the initial format?

Answer

Hope this helps

$str='[\n {\n "short_link" : "http:\/\/website.com\/img1085805",
\n "id" : "ca96c55e1aa76fbca17ee08cad7e5a15",
\n "thumb" : "http:\/\/images.website.com\/boxdata\/asset22114\/images\/thumb__chat_files_41.jpg?r=160421015318",
\n "type" : "img",\n "path" : "http:\/\/images.website.com\/boxdata\/asset22114\/images\/chat_files_41.jpg?r=160421015318",
\n "name" : "chat_files_41.jpg",\n "mime_type" : "image\/jpg"\n }\n]';
echo stripslashes(str_replace('\n','',$str));

check screenshot enter image description here