W3C validator: “Element head is missing a required instance of child element title”

混江龙づ霸主 提交于 2019-12-11 07:56:41

问题


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>

Update: I'm using PHP to generate parts of the file and it turns out this was the cause of the error.


回答1:


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>

I moved the first PHP tag down to the first line of the body and the validation passed.




回答2:


it is not giving error, instead of two warnings, i have checked in the same link.



来源:https://stackoverflow.com/questions/26394972/w3c-validator-element-head-is-missing-a-required-instance-of-child-element-tit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!