file_get_contents 返回 PHP 代码

use*_*380 5 php file-get-contents

当我file_get_contents()在本地文件上使用函数时,结果包含 php 代码,但我只需要 HTML。

正在读取的文件内容:

<?php echo '<p>Hello</p>';?>
Run Code Online (Sandbox Code Playgroud)

从位于同一文件夹中的不同文件调用 file_get_contents 的结果:

<?php echo file_get_contents('test.php'); //returns the following: string(31) "Hello'; ?>"
Run Code Online (Sandbox Code Playgroud)

如果我从外部服务器读取文件,它会返回 HTML - 正如我所期望的。所以问题是:如何从本地文件中获取 HTML 输出?谢谢你们。

Ste*_*eve 4

您可以使用文件 url (而不是文件路径),因此它由服务器处理,例如:

echo file_get_contents('http://website.com/test.php');
Run Code Online (Sandbox Code Playgroud)

但是 include/require 会更好,例如:

include 'test.php';
Run Code Online (Sandbox Code Playgroud)