Remove all backslashes from PHP urldecoded string

I am trying to remove all backslashes from a string with a url extension, but it outputs \ instead of outputting a string with a url extension with \ removed.

Please tell me my problem.

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

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

echo urldecode(stripslashes($json));

However, you should rather disable magic_quotes .

+11
source

Try this instead, your arguments for str_replace are incorrect.

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

php.net str_replace docs, - , , - , , , . , :

str_replace("\\","", $json)
+2

You are mistakenly using str_replace

str_replace("\\","", $json)
+1
source

This works 100% correctly.

$attribution = str_ireplace('\r\n', '', urldecode($attribution));
0
source

All Articles