哪些字符需要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 |
|
|