W3C验证出错

时间:2013-08-14 17:19:37

标签: html validation w3c

我正在尝试建立一个网站,但是当我尝试在W3C验证时,发生了2个错误:

 Line 28, Column 7: Stray end tag head.
</head>
Error Line 29, Column 6: An body start tag seen but an element of the same type was already open.
<body>

我的代码是:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="pt-br">
<!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>SpotBOT - Engenharia Mecânica Cotidiana</title>
<meta name="description" content="Página pessoal sobre enganharia mecânica, faculdade, dificuldades, trabalhos e realizações na área.">
<link rel="apple-touch-icon" href="/icon-iphone.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/icon-iphone4.png" />
<meta name="viewport" content="width=device-width">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="../css/main.css">
<script src="../js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<script src="../WYSIWYG/ckeditor.js"></script>
<?php
include("db_connect.php");
if (!isset($_SESSION)) session_start("Spotbot");
if(isset($_GET['page'])) {$page = $_GET['page'];}else {$page = "index";}
$query_select=mysql_query("SELECT permissao FROM indexpage WHERE pagename = '$page'")or print (mysql_error());;
if (mysql_num_rows($query_select) == 0){$nivel_necessario = 1;}
while($linha = mysql_fetch_array($query_select)){$nivel_necessario = $linha['permissao'];}
if(!isset($_SESSION['UsuarioID'])){$_SESSION['UsuarioNivel'] = "1";}
if ($_SESSION['UsuarioNivel'] < $nivel_necessario) {
session_destroy();
header("Location: http://spotbot.in?page=permission"); exit;
}
?>
<script>
    window.onload = function() {
        CKEDITOR.replace( 'texto' );
    };
</script>
</head>
<body>
<?php include_once("analyticstracking.php") ?>
<!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]--> 

<!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->
<div lang="pt-br" class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a>
      <?php include("menu.php");?>
    </div>
  </div>
</div>
<div class="container" lang="pt-br"> 
  <!-- Main hero unit for a primary marketing message or call to action -->
  <div class="hero-unit">
    <?php
            if(isset($_GET['page'])) {$page = $_GET['page'];}
            else {$page = "index";}
            $query_select=mysql_query("SELECT * FROM indexpage WHERE pagename = '$page'")or print (mysql_error());;
            if (mysql_num_rows($query_select) >= 1){
            while($linha = mysql_fetch_array($query_select)){
            $title = utf8_encode($linha["title"]);
            $text = utf8_encode($linha["text"]);
            $link= utf8_encode($linha["link"]);
            $button= utf8_encode($linha["button"]);
            }
                echo "<h2>$title</h2>
                <div id='post-data'><p>$text<br/></p></div>";
                if ($button != ""){echo "<p><a href='$link' class='btn btn-primary btn-large'>$button &raquo;</a></p>";}
                echo "</div><!-- Example row of columns --><div class='row'>";
            $query_select=mysql_query("SELECT * FROM indexfooter WHERE pagename = '$page'")or print (mysql_error());;
            while($linha = mysql_fetch_array($query_select)){
            $title = utf8_encode($linha["title"]);
            $text = utf8_encode($linha["text"]);
            $link= utf8_encode($linha["link"]);
            $button= utf8_encode($linha["button"]);
            echo "<div class='span4'><h3>$title</h3>
                <p>$text<br/>";
                if ($button != ""){echo "<p><a href='$link' class='btn'>$button &raquo;</a></p>";}
                echo "</div>";
            }}
            else
            {
                echo "
                <h2>Página não encontrada</h2>
                <p>A página que você procura não existe ou foi deletada.<br/>
                <p><a href='http://spotbot.in' class='btn'>Voltar à pagina principal &raquo;</a></p></div>
                </div><!-- Example row of columns --><div class='row'>";
            }
            ?>
  </div>
  <hr>
  <footer>
    <div id="geral">
    <p><a href="https://plus.google.com/107266754114799149959?rel=author">Me encontre no Google +</a></p>
    <p>Spotbot&copy;  2013</p>
    <p>All rights reserved.</p>    </div>
  </footer>
</div>
<!-- /container --> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="../js/vendor/jquery-1.8.3.min.js"><\/script>')</script> 
<script src="../js/vendor/bootstrap.min.js"></script> 
<script src="../js/plugins.js"></script> 
<script src="../js/main.js"></script> 
</body>
</html>

刚刚使用完整代码进行了编辑。

我正试图找到错误,但我找不到它。

请帮我找到这个bug;)

1 个答案:

答案 0 :(得分:4)

在您生成的actual HTML code生成的内容中,第23行以U + FEFF ZERO WIDTH NO-BREAK SPACE开头。它是一个不可见的控制字符,在HTML中完全有效,但它被视为数据字符。 head部分中的元素之间不允许使用除空格之外的任何数据字符(并且U + FEFF在定义中不是 HTML中的空格)。这意味着那里的任何数据字符(无论是U + FEFF还是FOOBAR)都会隐式关闭head元素并打开body元素(允许使用数据字符)。这解释了错误消息。

U + FEFF与Byte Order Mark(BOM)的字符相同。显然,.php文件一开始就以带有BOM的UTF-8格式保存。尽管BOM在UTF-8数据流的开头是完全合法的(并且通常是有用的),但它在其他地方具有不同的含义(作为数据字符)。 PHP处理器在插入.php文件的内容时无法删除BOM。

因此,应该通过在编辑器中打开db_connect.php文件并将其保存为UTF-8格式而不使用BOM 来解决问题。