php javascript url encoding

前端 未结 4 408
深忆病人
深忆病人 2020-12-24 12:49

I have a html text. I had encoded it in php using urlencode function. I want to decode that text in the javascript. when i use unescape function in javascript it replaces a

相关标签:
4条回答
  • 2020-12-24 13:07

    Parenthesis are exceptions to all of what is said in this post.

    geek mode on :

    false

    PHP rawUrlEncode() !== JavaScript encodeURIComponent()
    

    but true

    PHP rawUrlEncode() == JavaScript encodeURIComponent()
    

    In other words, there are many special characters that aren't treated as safe in rawurlencode when they are in encodeURIComponent.

    0 讨论(0)
  • 2020-12-24 13:10

    Try this:

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

    Source: http://phpjs.org/functions/urldecode:572

    0 讨论(0)
  • 2020-12-24 13:13

    Try using rawurlencode instead - urlencode does some things differently for "historical" reasons.

    See http://us.php.net/manual/en/function.urlencode.php for more information.

    0 讨论(0)
  • 2020-12-24 13:18

    PHP rawUrlEncode() == JavaScript encodeURIComponent()

    PHP rawUrlDecode() == JavaScript decodeURIComponent()

    0 讨论(0)
提交回复
热议问题