2010-03-31 100 views
35

我有一个xhtml页面在xhtml strict doctype下验证 - 但是,我得到了这个警告,我试图理解 - 并且正确。如何解决“在UTF-8文件中发现的字节顺序标记”验证警告

只是,我该如何找到这个错误的“字节顺序标记”。我正在使用Visual Studio编辑我的文件 - 不确定是否有帮助。

Warning Byte-Order Mark found in UTF-8 File.

The Unicode Byte-Order Mark (BOM) in UTF-8 encoded files is known to cause problems for some text editors and older browsers. You may want to consider avoiding its use until it is better supported.

回答

44

问题的位置部分很简单:byte-order mark(BOM)将在文件的开头。

编辑文件时,请转至File | Advanced Save Options...,您应该找到一个“编码”下拉列表(以及“行尾”下拉列表)。它可能设置为使用“Unicode(带签名的UTF-8) - Codepage 65001”。如果向下滚动一点点,可以找到“Unicode(不带签名的UTF-8) - Codepage 65001”。这应该做到这一点(如果你想)。如警告所示,有些系统可能会被UTF-8文件中的BOM所迷惑。

另请参阅Unicode网站关于BOM和UTF-8文件的常见问题解答。除了调出该文件实际上是UTF-8之外,它没有其他功能。特别是,它对字节顺序(我们有BOM的主要原因)没有影响,因为UTF-8的字节顺序是固定的。

+0

我打算为此投票,但我意外地投了票,并没有实现2天,现在它被锁定,它不会让我改变它......但这帮助我修复了w3c警告烦扰我,所以非常感谢。 – andygoestohollywood 2013-11-12 09:20:45

+1

@andygoestohollywood :-)感谢您的解释,当时我确实在想,为什么有人已经低估了答案。我可以编辑答案,以便撤消这个答案,但是我没有看到任何改变的建设性,我不喜欢将它推到“活跃”列表上以反转投票。我很高兴这有助于! – 2013-11-12 09:50:12

17

以下是我解决了这个问题:

  1. 下载并安装Notepad++

  2. 用记事本打开++

  3. 在菜单文件中选择“编码”,并设置为“编码没有BOM的UTF-8“

  4. 保存文件和BOM将会消失。

0

Linux的

公开赛Geany文件。

在菜单“Dokument”取消选中“编写Unicode物料清单”。

保存该文件。

0

BOM有时位于INSIDE文本中,而不是开始 - 如果某个文件已被其他文件组装一段时间,则使用例如include_once()。要删除它,请删除BOM之前的至少一个字符和BOM之后的至少一个字符之间的区域(以防万一)。 BOM的位置可以位于Internet Explorer的F12 Developer Tools中,也可能位于Edge中。它被形象化为黑色菱形/菱形

Visual Studio和WebMatrix可以保存有或没有签名的文件(在开始时)。

BOM导致验证(https://validator.w3.org/#validate_by_upload)期间或在控制台错误 - </HEAD>可以作为孤立的元件进行处理,而不< HEAD>,在显然的是本:

Error: Stray end tag head.

< BODY>作为第二个! < BODY>,当只有一个< BODY>存在,一切是正确的:

Error: Start tag body seen but an element of the same type was already open.

而且整个文档可以看出缺少DOCTYPE,当BOM或两个BOM小号占据第一线路和DOCTYPE是在第二行中,具有类似于此的消息:在IE F12开发人员工具控制台

Error: Non-space characters found without seeing a doctype first. Expected e.g. <!DOCTYPE html>.

Error: Element head is missing a required instance of child element title.

Error: Stray doctype.

Error: Stray start tag html.

Error: Stray start tag head.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute http-equiv not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Element link is missing required attribute property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Attribute name not allowed on element meta at this point.

Error: Element meta is missing one or more of the following attributes: itemprop, property.

Error: Element title not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Error: Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Error: Stray end tag head.

Error: Start tag body seen but an element of the same type was already open.

Fatal Error: Cannot recover after last error. Any further errors will be ignored.

https://validator.w3.org/#validate_by_uri

和消息流:

HTML1527: DOCTYPE expected. Consider adding a valid HTML5 doctype: "<!DOCTYPE html>".

HTML1502: Unexpected DOCTYPE. Only one DOCTYPE is allowed and it must occur before any elements.

HTML1513: Extra "<html>" tag found. Only one "<html>" tag should exist per document.

HTML1503: Unexpected start tag. HTML1512: Unmatched end tag.

开始时由一个BOM引起的一切。调试器在第一行显示一个黑色菱形。

保存有签名但未由php组装的文件不会导致此类错误,黑色钻石在IE调试器中不是易用的。所以也许php以某种方式转换BOM。看来,主要的PHP文件必须保存签名才能看到。

这些奇怪的字符出现在与include_once()合并的文件的开始和/或边界上,并且在没有签名前保存文件时不可见。这就是它指向BOM参与的原因。

我已经注意到这一切前天,当我开始转换我的网站到HTML5和验证。

BOM也可以在行首创建一个小缩进。两个文件包含相同的文本,但有一个缩进。

相关问题