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

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

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

header.php文件:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <header>
      <p> this should be on top</p>
    </header>

index.php文件:

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

<main>
  <p> this is the index</p>
</main>

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

footer.php:

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

</html>

如果我打开index.php它只会显示在index.php中写的是什么。我将所有文件保存在桌面上的文件夹中的文件夹中。

我只需拖动到浏览器(firefox)即可打开index.php。

php html require
1个回答
0
投票

您需要使用Web服务器运行PHP脚本。

在浏览器打开之前,PHP脚本需要由服务器解释。

要在本地运行您的项目,有多个应用程序,如Xampp(适用于Windows)或Mampp(适用于Mac),Docker或事件直接在您的计算机上安装Web服务器,安装Nginx或Apache。

© www.soinside.com 2019 - 2024. All rights reserved.