从PHP urldecoded字符串中删除所有反斜杠

时间:2022-08-09 18:02:45

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.

我试图从url解码的字符串中删除所有反斜杠,但它输出\而不是输出已删除的url解码字符串。

Please can you tell me my problem.

请你告诉我我的问题。

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

5 个解决方案

#1


11  

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

你想使用stripslashes(),因为它正是它的用途。看起来也更短:

echo urldecode(stripslashes($json));

You should however consider disabling magic_quotes rather.

但是你应该考虑禁用magic_quotes。

#2


2  

Try this instead, your arguments for str_replace are incorrect.

试试这个,str_replace的参数不正确。

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

#3


2  

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:

根据php.net的str_replace文档,第一个参数是你要搜索的,第二个是你要替换的,第三个是你要搜索的字符串。所以,你正在寻找这个:

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

#4


1  

You're wrongly using str_replace

你错误地使用了str_replace

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

#5


0  

This is working for 100% correctly.

这是正确的100%工作。

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

#1


11  

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

你想使用stripslashes(),因为它正是它的用途。看起来也更短:

echo urldecode(stripslashes($json));

You should however consider disabling magic_quotes rather.

但是你应该考虑禁用magic_quotes。

#2


2  

Try this instead, your arguments for str_replace are incorrect.

试试这个,str_replace的参数不正确。

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

#3


2  

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:

根据php.net的str_replace文档,第一个参数是你要搜索的,第二个是你要替换的,第三个是你要搜索的字符串。所以,你正在寻找这个:

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

#4


1  

You're wrongly using str_replace

你错误地使用了str_replace

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

#5


0  

This is working for 100% correctly.

这是正确的100%工作。

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