Javascript equivalent to php's urldecode()

前端 未结 3 1108
南方客
南方客 2020-12-08 13:41

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

相关标签:
3条回答
  • 2020-12-08 13:53

    I think you need the decodeURI function.

    0 讨论(0)
  • 2020-12-08 14:01

    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, ' '));
    }
    
    0 讨论(0)
  • 2020-12-08 14:18

    Check out this one

    function urldecode (str) {
      return decodeURIComponent((str + '').replace(/\+/g, '%20'));
    }
    
    0 讨论(0)
提交回复
热议问题