「带 BOM 的 UTF-8」和「无 BOM 的 UTF-8」有什么区别
2017-12-28 15:50
447 查看
「带 BOM 的 UTF-8」和「无 BOM 的 UTF-8」有什么区别?网页代码一般使用哪个?
链接:https://www.zhihu.com/question/20167122/answer/14194448来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
UTF-8 不需要 BOM,尽管 Unicode 标准允许在 UTF-8 中使用 BOM。
所以不含 BOM 的 UTF-8 才是标准形式,在 UTF-8 文件中放置 BOM 主要是微软的习惯(顺便提一下:把带有 BOM 的小端序 UTF-16 称作「Unicode」而又不详细说明,这也是微软的习惯)。
BOM(byte order mark)是为 UTF-16 和 UTF-32 准备的,用于标记字节序(byte order)。微软在 UTF-8 中使用 BOM 是因为这样可以把 UTF-8 和 ASCII 等编码明确区分开,但这样的文件在 Windows 之外的操作系统里会带来问题。
「UTF-8」和「带 BOM 的 UTF-8」的区别就是有没有 BOM。即文件开头有没有 U+FEFF。
UTF-8 的网页代码不应使用 BOM,否则常常会出错。这是一个小例子:
为什么这个网页代码 <head> 内的信息会被浏览器理解为在 <body> 内?
另附《The Unicode Standard, Version 6.0》之 3.10 D95 UTF-8 encoding scheme 的一段话:
While there is obviously no need for a byte order signature when using UTF-8, there are occasions when processes convert UTF-16 or UTF-32 data containing a byte order mark into UTF-8. When represented in UTF-8, the byte order mark turns into the
byte sequence. Its usage at the beginning of a UTF-8 data stream is neither required nor recommended by the Unicode Standard, but its presence does not affect conformance to the UTF-8 encoding scheme. Identification of the byte sequence at the beginning of
a data stream can, however, be taken as a near-certain indication that the data stream is using the UTF-8 encoding scheme.
http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf
相关文章推荐
- utf 8无bom和utf 8什么区别
- UTF-8(无BOM)和UTF-8这两个有什么区别呢?
- UTF-8(无BOM)和UTF-8这两个有什么区别呢
- 「带 BOM 的 UTF-8」和「无 BOM 的 UTF-8」有什么区别?网页代码一般使用哪个?
- (转)ansi,gb2312,gbk,gb18030,unicode,utf-8,unicode big endian编码的区别及什么是BOM
- 「带 BOM 的 UTF-8」和「无 BOM 的 UTF-8」有什么区别?
- UTF-8(无BOM)和UTF-8这两个有什么区别呢?
- UTF-8 和UTF8和utf-8和utf8有什么区别 ?
- UTF-8和GBK有什么区别
- Windows 记事本的 ANSI、Unicode、UTF-8 这三种编码模式有什么区别?
- DOM, DOCUMENT, BOM, WINDOW 有什么区别?
- Unicode、UTF-8 和 ISO8859-1到底有什么区别
- DOM, DOCUMENT, BOM, WINDOW 有什么区别?
- UTF-8和GBK有什么区别?到底用哪个好?
- php基础系列:utf-8与utf-8(无BOM)的区别?
- 趣谈unicode,ansi,utf-8,unicode big endian这些编码有什么区别
- utf-8 ie6 乱码 Unicode签名bom 什么是bom?
- 趣谈unicode,ansi,utf-8,unicode big endian这些编码有什么区别
- UTF-8格式编码与UTF-8无BOM格式编码的区别(包括java文件)
- utf-8 和 utf8 有什么区别