找回密码
 新建账号

[JS] 地址栏字符编码方法 urlencode()字符表

[复制链接]
php 发表于 2012/11/5 10:02 | 显示全部楼层 |阅读模式
哪些字符需要urlencode编码?具体怎么处理?
JS用escape()/encodeURI()/encodeURIComponent()方法编码,用unescape()/decodeURI()/ecodeURIComponent()解码.

escape()/encodeURI()/encodeURIComponent()的区别:
encodeURI()不编码82个字符!#$&'()*+-./:;=?@_~0-9a-zA-Z
encodeURIComponent()不编码71个字符! '()*-._~0-9a-zA-Z
escape()不编码69个字符*+-./@_0-9a-zA-Z

如果发送页面和接收页面的charset是一样的,只需要用escape()即可,如果发送页面是gb2312,而接收页面是utf-9,就要用encodeURI()/encodeURIComponent(),他们的区别在于,后者编码的字符更多.如果要传递内容而非地址栏参数,请使用encodeURIComponent().

PHP用urlencode()不编码,用urldecode()解码.或者用rawurlencode()编码,用rawurldecode()解码
区别在于rawurlencode()编码的字符更多,包括除-_.以外的所有字符,而urlencode()只编码-_. 之外的非字母非数字字符.特殊字符地址栏编码表
空格%20
!%21
#%23
$%24
%%25
&%26
'%27
(%28
)%29
*%2A
+%2B
,%2C
.%2E
/%2F
:%3A
;%3B
=%3D
?%3F
@%40
[%5B
\%5C
]%5D

手机版|轻松E站

GMT+8, 2024/4/25 09:10

快速回复 返回顶部 返回列表