問題描述:在使用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 Western union customer service stream defined in that protocol.
解決方案:
•配置EditPlus,刪除BOM:“工具->首選項->文件->UTF-8標識->總是刪除簽名”,對應的英文版EditPlus路徑為“Tools->Preferences->Files->UTF-8 signature->Always remove signature”
•改用其他編輯工具,推薦VIM
•轉換為ASCII格式