文件头出现的BOM问题

问题描述:在使用EditPlus等文本编辑工具,在windows下修改编码格式为UTF-8的文档时,会在文件的开头阐产生<feff>的字符。

 

问题影响:用IE浏览页面时,顶部会出现一行空白,查看页面的DOM结构,会发现其中的<link><script>标签会被解析到<body>标签下,在IE下,<meta>标签页会被解析到<body>标签下。


问题原因:在Windows标准下的UTF-8编码文档,是以<feff>开头来标识的,成为BOM(Byte Order Mark,字节序标记)。
文档摘录:
Q: What is a BOM?
A: A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may be mandatory (or prohibited) in the Unicode data stream defined in that protocol.


解决方案:
配置EditPlus,删除BOM:“工具->首选项->文件->UTF-8标识->总是删除签名”,对应的英文版EditPlus路径为“Tools->Preferences->Files->UTF-8 signature->Always remove signature”
改用其他编辑工具,推荐VIM
转换为ASCII格式

猜你喜欢

转载自magicyang919.iteye.com/blog/1739069