php/html:要求在基本 html / php 代码中不起作用
php/html: Require doesn't work in basic html / php code
所以我试图将 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。
您需要使用 Web 服务器 运行 您的 PHP 脚本。
PHP脚本在被浏览器打开之前需要被服务器解释。
为了 运行 在本地您的项目有多个应用程序,例如 Xampp(对于 Windows)或 Mampp(对于 Mac)、Docker 或事件直接在 Machine 中安装 Web 服务器,安装 Nginx 或 Apache。
所以我试图将 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。
您需要使用 Web 服务器 运行 您的 PHP 脚本。
PHP脚本在被浏览器打开之前需要被服务器解释。
为了 运行 在本地您的项目有多个应用程序,例如 Xampp(对于 Windows)或 Mampp(对于 Mac)、Docker 或事件直接在 Machine 中安装 Web 服务器,安装 Nginx 或 Apache。