php javascript url编码

And*_*eda 26 javascript php urlencode

我有一个HTML文本.我使用urlencode函数在php中对其进行了编码.我想在javascript中解码该文本.当我在javascript中使用unescape函数时,它会替换所有特殊字符,但sapce将替换为"+".我怎样才能正确地做到这一点,以便空间被替换为空间本身?

Lam*_*amy 51

PHP rawUrlEncode()== JavaScript encodeURIComponent()

PHP rawUrlDecode()== JavaScript decodeURIComponent()

  • 不幸的是,对于某些角色来说,这个答案是错 在php`rawurlencode(")")=="%29"`在javascript中`encodeURIComponent(")")==")"`. (4认同)
  • 知道php urlencode与javascript不兼容所以你应该使用rawUrlEncode代替 (2认同)
  • @RégisB.为符合RFC 3986,对[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)进行了修复.在底部有一个名为`fixedEncodeURIComponent`的函数 (2认同)

Dav*_*ave 17

尝试使用rawurlencode - urlencode因"历史"原因而做了一些不同的事情.

有关更多信息,请参见http://us.php.net/manual/en/function.urlencode.php.