Javascript 相当于 php 的 urldecode()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3431512/
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
Javascript equivalent to php's urldecode()
提问by Derek Adair
I wrote a custom xml parser and its locking up on special characters. So naturally I urlencoded them into my database.
我编写了一个自定义的 xml 解析器并锁定了特殊字符。所以很自然地我将它们编码到我的数据库中。
I can't seem to find an equivalent to php's urldecode().
我似乎找不到相当于 php 的urldecode().
Are there any extentions for jqueryor javascript that can accomplish this?
jquery或 javascript是否有任何扩展可以实现这一点?
回答by kennytm
You could use the decodeURIComponentfunctionto convert the %xx into characters. However, to convert +into spaces you need to replace them in an extra step.
您可以使用该decodeURIComponent函数将 %xx 转换为字符。但是,要转换+为空格,您需要在额外的步骤中替换它们。
function urldecode(url) {
return decodeURIComponent(url.replace(/\+/g, ' '));
}
回答by Shahzeb chohan
Check out this one
看看这个
function urldecode (str) {
return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}
回答by shabunc
I think you need the decodeURIfunction.
我认为你需要这个decodeURI功能。

