Javascript equivalent to php's urldecode() Javascript equivalent to php's urldecode() javascript javascript

Javascript equivalent to php's urldecode()


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


Check out this one

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


I think you need the decodeURI function.