2011-12-20 52 views
2

如何以編程方式將動態PHP文件轉換爲靜態HTML文件,顯然將所有動態PHP相關值作爲靜態HTML進行烘焙?PHP - 如何以編程方式烘烤靜態HTML文件?

+1

複製輸出,所生成的網頁的HTML源代碼!也許你的意思是*如何在運行時自動執行此操作*? – 2011-12-20 16:00:52

+0

自動是。 – 2011-12-20 16:01:12

+0

聽起來像你正在尋找緩存信息,請點擊此處:http://www.slideshare.net/anisniit/caching-new – 2011-12-20 16:02:34

回答

1

在瀏覽器中查看HTML源代碼並將其保存。

如果您想自動執行此操作,請使用output buffering

0

最簡單的方法是打開頁面,並複製「查看源文件」
您還可以使用
PHP函數$homepage = file_get_contents('http://www.example.com/');

,並將其保存在一個文件

0

從相關文章:

<?php 
    job_start(); // your PHP/HTML code here 
    file_put_contents('where/to/save/generated.html', ob_get_clean()); 
?> 
+0

'ob_start();'也是需要的。 – 2011-12-20 16:04:14

1
<?php 

ob_start(); // start output buffering 

echo "your html and other PHP"; // write to output buffer 

file_put_contents("file.html", ob_get_contents()); // write the contents of the buffer to file 

ob_end_clean(); // clear the buffer 
1

某處你的PHP文件的頂部:

ob_start(); 

所有處理後:

$output = ob_get_clean(); 
file_put_contents('filename', $output); 

如果你再還希望將它輸出該進程(例如,如果您想要在運行時寫入緩存,還要向該用戶顯示該頁面:

echo $output; 
0

您可以LSO與wget的

做例如:

$ wget -rp -nH --cut-dirs=1 -e robots=off http://www.domain.com/