从 PHP urldecoded 字符串中删除所有反斜杠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5930828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove all backslashes from PHP urldecoded string
提问by max_
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, "\"));
?>
回答by mario
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_quotesrather.
但是,您应该考虑禁用 magic_quotes。
回答by Fosco
Try this instead, your arguments for str_replace are incorrect.
试试这个,你的 str_replace 参数不正确。
<?php
$json = $_GET['ingredients'];
echo urldecode(str_replace("\","",$json));
?>
回答by thefugal
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 docs,第一个参数是您要搜索的内容,第二个是您要替换的内容,第三个是您要搜索的字符串。所以,您正在寻找这个:
str_replace("\","", $json)
回答by Riccardo Galli
You're wrongly using str_replace
你错误地使用了 str_replace
str_replace("\","", $json)
回答by Khandad Niazi
This is working for 100% correctly.
这是 100% 正确的。
$attribution = str_ireplace('\r\n', '', urldecode($attribution));