我正在尝试从php文件中获取Html源代码并使用它将其放入Html文件中:
file_put_contents('result.html', file_get_contents('index.php'));
运行此函数后,“result.html”将在原始“index.php”文件中包含相同的PHP代码,而我需要“result.html”文件来获取index.php执行后的Html代码。 请帮忙吗?感谢。
答案 0 :(得分:5)
您只是将PHP代码复制到html文件中。
获取需要解释php文件的html源代码
这样做的一种方法是:
file_put_contents('result.html', file_get_contents('http://localhost/path/to/index.php'));
答案 1 :(得分:4)
另一种方式(不需要http服务器也不需要访问shell):
<?php
ob_start();
include('index.php');
$page = ob_get_contents();
ob_end_clean();
file_put_contents('result.html', $page);
?>
答案 2 :(得分:2)
使用此代码
file_put_contents('result.html', file_get_contents('http://localhost/yourproject/index.php'));
答案 3 :(得分:1)
您可以尝试:
file_put_contents('result.html', shell_exec('php path/to/index.php'));