2016-11-13 42 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獲取更多信息。