Remove all backslashes from PHP urldecoded string

max_ picture max_ · May 9, 2011 · Viewed 28.6k times · Source

I am trying to remove all backslashes from a url-decoded string, but it is outputting \ rather than outputting the url-decoded string with \ removed.

Please can you tell me my problem.

<?php
$json = $_GET['ingredients'];
echo urldecode(str_replace($json,$json, "\\"));
?>

Answer

mario picture mario · May 9, 2011

You want to use stripslashes(), because that's exactly what it is for. Also looks shorter:

echo urldecode(stripslashes($json));

You should however consider disabling magic_quotes rather.