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也可以在行首创建一个小缩进。两个文件包含相同的文本,但有一个缩进。
我打算为此投票,但我意外地投了票,并没有实现2天,现在它被锁定,它不会让我改变它......但这帮助我修复了w3c警告烦扰我,所以非常感谢。 – andygoestohollywood 2013-11-12 09:20:45
@andygoestohollywood :-)感谢您的解释,当时我确实在想,为什么有人已经低估了答案。我可以编辑答案,以便撤消这个答案,但是我没有看到任何改变的建设性,我不喜欢将它推到“活跃”列表上以反转投票。我很高兴这有助于! – 2013-11-12 09:50:12