程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> 文件頭出現的BOM問題

文件頭出現的BOM問題

編輯:PHP基礎知識
 

問題描述:在使用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格式
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved