简体   繁体   中英

Remove \" from a JSON response in PHP?

"image_url":"\\" http://gfgfgfg.com/wjjjj/kjjk/2014/08/LOGO-1024x1024.jpg \\""

I had the above result in json response, but it shows \\" in front and back of the url. I just want to remove it from the result.

I saw the .gsub() in Ruby, but I want to remove \\" using PHP. str_replace('\\"','',$string) does not working :

 $image_rul=trim(str_replace(array('=','\"'), '', $i_url));

Use this,

$var = '"image_url":"\"http://gfgfgfg.com/wjjjj/kjjk/2014/08/LOGO-1024x1024.jpg\""';
$result =  str_replace('\"','',$var);

Result = "image_url":" http://gfgfgfg.com/wjjjj/kjjk/2014/08/LOGO-1024x1024.jpg "

    $var = '"image_url":"\"http://gfgfgfg.com/wjjjj/kjjk/2014/08/LOGO-1024x1024.jpg\""';
    $result =  str_replace('\\','',$var);
    echo $result =  str_replace('"','',$result);

result = image_url: http://gfgfgfg.com/wjjjj/kjjk/2014/08/LOGO-1024x1024.jpg

You can use stripslashes for this purpose.

See this for more clarification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM