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, "\\"));
?>
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.
Try this instead, your arguments for str_replace are incorrect.
<?php
$json = $_GET['ingredients'];
echo urldecode(str_replace("\\","",$json));
?>
Accoring to php.net's str_replace docs, the first argument is what you are searching for, the second is what you are replacing with, and the third is the string you are searching in. So, you are looking for this:
str_replace("\\","", $json)
You're wrongly using str_replace
str_replace("\\","", $json)
This is working for 100% correctly.
$attribution = str_ireplace('\r\n', '', urldecode($attribution));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With