单个页面中有多个标签

时间:2014-07-11 21:50:43

标签: javascript php

我对PHP很新。我一直在开发一个PHP网站代码,需要一个通用的头文件(header.php)。我在content.php中包含了常见的header.php页面。现在我在HTML视图源中看到了2 2和2个标签。

代码是这样的 -

<?php
      include "header.php";

      //some php code.
?>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

在页面源代码中,我的代码如下所示,

<html>
<head> <script src="header.js"> </script></head>
   <body>
        <h1> Menu Page </h1>
   </body>
</html>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

请建议此代码是否正常或多个html或head标签对SEO和/或性能不利。另外请建议解决方法。

6 个答案:

答案 0 :(得分:2)

不,每页只能有一个<HTML>

您正在寻找的是“布局模式”。

<!DOCTYPE HTML>
<HTML>

    <HEAD>
        <!-- your link to stylesheet, jquery etc -->
    </HEAD>

    <BODY>
        <!-- here include your header -->

        <!-- and your content -->
    </BODY>

</HTML>

标题和内容都没有<HTML>或其他内容 - 它只是<DIV>等。

如果您正在努力使用基本的HTML格式,可以使用以下 basic html templates


对于任何更大的应用程序,使用框架(例如Laravel)和一些模板引擎是有意义的。

但是,对于这个简单的例子,你可以这样:

[file index.php]
- resolve what content to show based on $_GET
- include layout, tell it what title and content to show

[layout]
as shown above, add into <head> a <title> tag
in body, include the content files

[additional files for content, header etc]
...

答案 1 :(得分:1)

没有。你只能有一套

<html> </html>

标签

答案 2 :(得分:1)

根据定义,Html文档正好包含1个HTML标记,其中包含头部和正文标记。所以你的代码不是有效的HTML。

答案 3 :(得分:1)

我认为这就是你要找的东西:

您的header.php应包含以下html

<html>
   <head>
     <title></title>
     ....
   </head>
   <body>

现在,您的body page应仅包含divs,且内容仅包含<body></body>

然后你有footer.php像这样结束html:

   </body>
</html>

因此,在您的主体文件中,您将拥有以下内容:

<?php
   include "header.php";

   //some php code.
?>

<h1> Test Page </h1>

<?php
   include "footer.php";
?>

答案 4 :(得分:1)

您应该只使用一个<html><head><body><h1>标记来编写有效的html代码。

如果您尝试使用php构建类似引擎的模板,您可以像这样构建它:

的header.php

<!DOCTYPE HTML>
<html>
<head>
    <script src="my.js"></script>
</head>
<body>

的index.php

<?php
     include_once("header.php");
?>
<h1><?php echo $page_title; ?></h1>

<div class="main">
    <p>This is my Content</p>
</div>

<?php
    include_once("footer.php");
?>

footer.php

<script src="additional.js"></script>
</body>
</html>

答案 5 :(得分:0)

您需要在header.php中删除html和body标签等。这将解决您的问题

相关问题