本文介绍了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().

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

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

推荐答案

你可以使用将%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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 03:03