str replace - 从 PHP url 解码字符串中删除所有反斜杠


str replace - Remove all backslashes from PHP urldecoded string

我正在尝试从 url 解码的字符串中删除所有反斜杠,但它正在输出 '' 而不是输出 url 解码的字符串,并删除 ''。

请你告诉我我的问题。

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

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

echo urldecode(stripslashes($json));

但是,您应该考虑禁用magic_quotes。

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

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

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

str_replace("''","", $json)

你错误地使用了str_replace

str_replace("''","", $json)

这是 100% 正确工作。

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