要求在基本的html / php代码中不起作用

问题描述 投票:0回答:2

所以我试图将header.php导入我的index.php文件文件,但它只是不起作用。

index.php文件:

<?php
require "header.php";

 ?>

    <main>
      <p> online! </p>
      <p> offline! </p

    </main>


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

header.php文件:

<!DOCTYPE html>
<html>
  <head>

  </head>

  <body>
    <header>


      <p> this should be on top</p>


    </header>

  </body>

</html>

页脚:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <p> This should be on the bottom </p>
</body>

</html>

当我打开项目时,我只会看到索引中没有页眉或页脚的内容

php html require
2个回答
1
投票

您的代码返回无效的HTML,因为DOCTPYE,html,head和body定义了两次。

将header.php更改为:

<!DOCTYPE html>
<html>
  <head>
  </head>

  <body>
    <header>
      <p> this should be on top</p>
    </header>

  #-- not closing body and html

将footer.php更改为:

<p> This should be on the bottom </p>
</body>
</html>

0
投票

确保你的pathheaderfooter是正确的。然后尝试将其包含在您的页面中

require(“header.php”);

//Your html code here

require(“footer.php”);
© www.soinside.com 2019 - 2024. All rights reserved.