PHP文件\u放置\u从PHP文件保存的内容

PHP文件\u放置\u从PHP文件保存的内容,php,file-get-contents,Php,File Get Contents,我试图从php文件中获取Html源代码,并使用以下方法将其放入Html文件: file_put_contents('result.html', file_get_contents('index.php')); 运行此函数后,“result.html”将在原始“index.PHP”文件中包含相同的PHP代码,而我需要“result.html”文件在index.PHP执行后获取html代码。 需要帮忙吗?。谢谢。您只是将php代码复制到html文件中 要获取html源代码,您需要解释php文件 一

我试图从php文件中获取Html源代码,并使用以下方法将其放入Html文件:

file_put_contents('result.html', file_get_contents('index.php'));
运行此函数后,“result.html”将在原始“index.PHP”文件中包含相同的PHP代码,而我需要“result.html”文件在index.PHP执行后获取html代码。
需要帮忙吗?。谢谢。

您只是将php代码复制到html文件中

要获取html源代码,您需要解释php文件

一种方法是:

file_put_contents('result.html', file_get_contents('http://localhost/path/to/index.php'));
使用此代码

file_put_contents('result.html', file_get_contents('http://localhost/yourproject/index.php'));
您可以尝试:

file_put_contents('result.html', shell_exec('php path/to/index.php'));
另一种方式(不需要http服务器,也不需要访问shell):



您将希望通过HTTP为文件提供服务,以获取浏览器将看到的内容,或者以其他方式在文件中执行PHP。当我将整个URL放入result.html文件中时,它不会在其中写入任何内容!。还是0kb。有什么帮助吗?在php.ini中设置/检查
allow\u url\u fopen=On
当我把整个url放在result.html文件中时,它不会写任何东西!。还是0kb。有什么帮助吗?谢谢,它实际上解决了我脚本中的两个问题:)最佳答案+1
<?php

ob_start();
include('index.php');
$page = ob_get_contents();
ob_end_clean();

file_put_contents('result.html', $page);

?>