问题描述
我正在尝试使用W3C验证器在。当我使用直接输入运行下面的代码时,我收到错误消息,例如元素头缺少必需的子元素标题和 Stray开始标记html 。这让我感到困惑,因为< html>
标签就在那里。为什么验证者不能看到它?
I'm trying to validate my document for HTML5 using the W3C validator at http://validator.w3.org/check. When I run the code below using "direct input" I get error messages like Element head is missing a required instance of child element title and Stray start tag html. This baffles me, because the <html>
tag is right there. Why can't the validator see it?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="some content">
<title>page title</title>
</head>
<body>
</body>
</html>
更新:我正在使用PHP生成部分文件,事实证明这是错误的原因。
Update: I'm using PHP to generate parts of the file and it turns out this was the cause of the error.
推荐答案
我发现了错误。我正在使用PHP来生成页面。当我在十六进制编辑器中查看它时,我在标记之前发现了两个空字节(十六进制代码0x00)。正好在我的第一个<?php?>
标签的位置。当我复制代码或通过URL运行代码时,验证器遇到空字节。当我手动编写代码时,它验证正常。
I discovered the error. I'm using PHP to generate the page. When I viewed it in a hex editor I discovered two null bytes (hex code 0x00) before the tag. Exactly where my first <?php ?>
tag were. When I copied the code or ran it by URL, the validator encountered the null bytes. When I wrote the code manually, it validated fine.
<!DOCTYPE html>
<?php
/* the PHP tag apparently outputs two null bytes */
?>
<html>
<head>
<title>page title</title>
</head>
<body>page body</body>
</html>
我将第一个PHP标记移动到正文的第一行并验证通过。
I moved the first PHP tag down to the first line of the body and the validation passed.
这篇关于W3C验证器:“元素头缺少必需的子元素标题实例”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!