Posted in 2010/05/31 ¬ 19:05h.yongbin
URL中,什么字符需要编码?
关于URL编码,RFC1738做了如下的规定:
“Only alphanumerics [0-9a-zA-Z], the special characters “$-_.+!*’(),” [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL.”
RFC继而说明了保留字、特殊符号、不安全字符的含义——也就是说,下面三类字符可以不经过编码,直接出现在URL上:
[0-9a-zA-Z]
特殊字符:$-_.+!*’(),
保留字符:&/:;=?@
为了让我们思路更清晰,我们再总结一下,哪些字符必须要编码:
ASCII表中没有对应可显示字符的,例如汉字
不安全字符,包括:#”%<>[]{}|\^`~
不当做保留字符来使用的保留字符,即&/:;=?@
Read the rest of this entry »
Posted in 2010/05/28 ¬ 10:32h.yongbin
Web开发中,文档常常指:(X)HTML文档、XML文档、CSS文档、js文档。指定文档编码的方式有以下几种:
HTTP Header中指定文档编码
在一个典型的HTTP响应头里,Content-Type的值中可以指定文档编码,如:
HTTP/1.1 200 OK
Date Tue, 11 May 2010 04:09:22 GMT
Server Apache
Content-Type text/html; charset=gb2312
对于动态网页,用这种方式指定文档编码,在脚本中直接输出响应头即可:
header( ‘Content-type: text/html; charset=gb2312′ );
对于静态网页、CSS文件等,则需要在Apache等服务器中配置,例如:
AddType ‘text/html; charset=gb2312′ html
Content-Type meta元素中指定HTML文档编码
Read the rest of this entry »