2016-11-13 99 views
-1

我刚开始学习php,并且创建了一个动态创建页面的php页面。例如我已经使用包括menu.php,header.php等。 我想php来自动创建一个包含呈现的PHP的HTML文件。如何让php用渲染的php代码创建html文件?

我的项目: 每当我刷新索引页面时完全不同的内容加载,我想自动创建一个html版本。

+0

请详细解释一下你想要什么,尝试在线搜索,http://stackoverflow.com/questions/3787125/how-to-cache-dynamic-php-page可能是你想要的 – Blag

+0

你真的需要更好地解释这个问题。如果有意义,请给出一个有效的使用场景和可能的一些屏幕截图。 – Shawn

回答

0

如果我理解正确,您希望将PHP脚本生成的输出存储到文件中,对不对?在这种情况下,你可以使用输出缓冲:

<?php 
// Turn on output buffering 
ob_start(); 

// Create the HTML page content 
print '<!DOCTYPE html><html><head><title>test</title></head><body><button type="button">Button</button></body></html>'; 

// At the end of the PHP script, write the buffered content to a file 
$content = ob_get_clean(); 
file_put_contents('/my/html/pages/page.html', $content); 

// Output the HTML to the browser 
print $content; 
?> 

访问php.net获取更多信息。