file_get_contents返回PHP代码 [英] file_get_contents returns PHP code
问题描述
当我在本地文件上使用file_get_contents()
函数时,虽然我只需要HTML,但是结果包含php代码.
When I use file_get_contents()
function on a local file, the result contains php code, though I need HTML only.
正在读取的文件内容:
<?php echo '<p>Hello</p>';?>
从位于同一文件夹中的另一个文件中调用file_get_contents的结果:
And the result of file_get_contents called from a different file located in the same folder:
<?php echo file_get_contents('test.php'); //returns the following: string(31) "Hello'; ?>"
如果我从外部服务器读取文件,它将返回HTML-正如我期望的那样.所以问题是:如何从本地文件获取HTML输出?谢谢大家.
If I read a file from an external server, it returns HTML - as I would expect. So the question is: how do I get HTML output from the local file? Thank you all.
推荐答案
您可以使用文件url(而非文件路径),因此它由服务器处理,例如:
You can use the files url (not filepath), so it is processed by the server eg:
echo file_get_contents('http://website.com/test.php');
但是包含/要求会更好,例如:
However include/require would be better, eg:
include 'test.php';
这篇关于file_get_contents返回PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!