Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all backslashes from PHP urldecoded string

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, "\\"));
?>
like image 868
max_ Avatar asked May 08 '11 22:05

max_


5 Answers

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.

like image 159
mario Avatar answered Sep 30 '22 04:09

mario


Try this instead, your arguments for str_replace are incorrect.

<?php
$json = $_GET['ingredients'];
echo urldecode(str_replace("\\","",$json));
?>
like image 43
Fosco Avatar answered Sep 30 '22 03:09

Fosco


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)
like image 42
thefugal Avatar answered Sep 30 '22 04:09

thefugal


You're wrongly using str_replace

str_replace("\\","", $json)
like image 28
Riccardo Galli Avatar answered Sep 30 '22 04:09

Riccardo Galli


This is working for 100% correctly.

$attribution = str_ireplace('\r\n', '', urldecode($attribution));
like image 31
Khandad Niazi Avatar answered Sep 30 '22 03:09

Khandad Niazi