Question

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

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

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

Was it helpful?

Solution

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, ' '));
}

OTHER TIPS

Check out this one

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

I think you need the decodeURI function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top