PHP file_put_contents从php文件保存 [英] PHP file_put_contents save from php file
本文介绍了PHP file_put_contents从php文件保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从php文件中获取HTML源代码,并使用以下代码将其放入HTML文件中:
I'm trying to get the Html source code from a php file and put it into an Html file using this:
file_put_contents('result.html', file_get_contents('index.php'));
运行此函数后,"result.html"将在原始"index.php"文件中包含相同的PHP代码,而我需要"result.html"文件以在执行index.php之后获取HTML代码. 有任何帮助吗?谢谢.
After running this function, The "result.html" will contain the same PHP codes in the original "index.php" file, While I need "result.html" file to get the Html code after index.php has executed. Any Help Please?. Thanks.
推荐答案
另一种方式(不需要http服务器也不需要访问shell):
Another way (doesn't need an http server nor access to shell):
<?php
ob_start();
include('index.php');
$page = ob_get_contents();
ob_end_clean();
file_put_contents('result.html', $page);
?>
这篇关于PHP file_put_contents从php文件保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文