Javascript相当于php的urldecode() [英] Javascript equivalent to php's urldecode()

查看:152
本文介绍了Javascript相当于php的urldecode()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个自定义xml解析器并锁定了特殊字符。所以我很自然地将它们编码到我的数据库中。

I wrote a custom xml parser and its locking up on special characters. So naturally I urlencoded them into my database.

我似乎无法找到与PHP相同的 urldecode()

I can't seem to find an equivalent to php's urldecode().

jquery 或javascript是否有任何扩展可以完成这个?

Are there any extentions for jquery or javascript that can accomplish this?

推荐答案

你可以使用 decodeURIComponent 函数将%xx转换为字符。但是,要将 + 转换为空格,您需要在额外的步骤中替换它们。

You could use the decodeURIComponent function to convert the %xx into characters. However, to convert + into spaces you need to replace them in an extra step.

function urldecode(url) {
  return decodeURIComponent(url.replace(/\+/g, ' '));
}

这篇关于Javascript相当于php的urldecode()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆