1

我正在尝试建立一个网站,但是当我尝试在 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>

刚刚用完整的代码编辑。

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

请帮我找到这个错误;)

4

1 回答 1

4

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

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

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

于 2013-08-14T18:17:09.493 回答