php - 我似乎无法在 header.php 上动摇验证错误(如 "Stray start tag html")

标签 php html html-parsing w3c-validation

运行验证并出现一些错误。

    f<!DOCTYPE html>↩
    <!--[if IE 8 ]><html class="ie ie8 no-js" lang="en-US" prefix="og: http://ogp.me/ns#"> <![endif]-->↩
    <!--[if (gte IE 9)|!(IE)]><!--><html class="no-js" lang="en-US" prefix="og: http://ogp.me/ns#"> <!--<![endif]-->↩
    <head>↩

我尝试将 header.php 保存为(UTF-8,无 BOM),但我似乎无法在开始时改变非空格字符(“f”)。

这是 PHP 代码:

<!DOCTYPE html>
<?php
/**
 * Theme Header
 *
 * Outputs <head> and header content (logo, tagline, navigation)
 */
?>
<!--[if IE 8 ]><html class="ie ie8 no-js" <?php language_attributes(); ?>> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html class="no-js" <?php language_attributes(); ?>> <!--<![endif]-->
<head>

然后,我不知道从哪里开始处理“stray html”错误标签。自己检查一下http://wsumc.com/worship

最佳答案

查看 https://validator.w3.org/nu/?doc=http://wsumc.com/worship/ ...

“杂散开始标记 html ”消息只是 f 的另一个副作用。在开始时。

HTML 的工作方式是 f是赤裸裸的文本——head元素不能包含 - 因此这意味着文档的正文已经开始,并且后面的所有内容都是正文的一部分。因此,当 HTML 解析器看到 f 时,解析器生成 <body>开始标记。

但是解析器看到的下一件事是 <!DOCTYPE html> —现在位于 body - 所以解析器会说,“Stray doctype”并继续前进。但接下来解析器发现的是 <html>开始标记,现在也位于 body 中- 所以解析器会说,“杂散开始标记 html

Parsing HTML documents section of the HTML spec定义了这一切是如何工作的(尽管对于大多数读者来说,这并不是一种 super 平易近人的方式……)

关于php - 我似乎无法在 header.php 上动摇验证错误(如 "Stray start tag html"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43258802/

相关文章:

php - 为什么它输出: the query is empty

html - 使用填充与高度(使用 vh)与最小高度定义网页中部分高度的最佳做法是什么

php - PDO PHP - PDOException - 数值超出范围 : 1264 Out of range value for column 'customer_id' at row 1

php - htaccess 在一台服务器上工作正常并在另一台服务器上导致重定向循环

javascript - 使用 Javascript : How to create a 'Go Back' link that takes the user to a link if there's no history for the tab or window?

html - 位置 : sticky not working in some device

java - Jsoup - 从 href 属性中选择值

c# - 将 HTML 表格解析为 CSV 的最佳方法

java - 从 TD 标签中解析 Html 文本

没有 cURL 的 PHP4 HTTP 发布