html>
{title}{content}
tmp.html是模板文件
/*
*?說明:生成靜態頁面,tmp.html是模板文件,news.html是要生成的文件,
*
*/
//1,先讀取模板中內容
$str=file_get_contents('tmp.html');
//2,將指定的內容進行替換
$title='網站標題';
$content='網站內容';
//title和content變量可以是從數據庫中讀取的內容,在此只是舉例
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
//3,將替換后的內容寫入新文件
file_put_contents('news.html',$str);
demo.php是要執行的php腳本程序
html>
網站標題網頁內容
news.html是程序執行完成生成的靜態文件