PHP 外部文件包含

PHP External File Inclusion

我有一个外部 PHP 文件 "test.php" 像这样:

echo "Hello";

我还有一个 html 文件,元素中包含此 PHP 脚本:

<?php include("test.php"); ?>

而不是得到 "hello" html 页面有 "echo "你好";"

如何才能让 include 语句实际执行 PHP,而不只是显示实际代码?

当您包含一个文件时,PHP 的解释器不会假定它是 PHP 代码。您可以包含纯文本或二进制数据或...任何东西,真的。

test.php 中的代码周围放置 <?php … ?> 标签。