PHP生成靜態HTML頁面簡單方法
阿新 • • 發佈:2019-02-15
PHP檔名:dome.php
<?php
$string = 1;
ob_start();
@readfile("templets/list.html");
$text = ob_get_flush();
$myfile = fopen("list.html","w");
$text = str_replace ("{counent}",$string,$text);
fwrite($myfile,$text);
ob_clean();
?>
模板檔名:templets/list.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
<table width="500" border="0" cellpadding="5" cellspacing="1" align="center" bgcolor="#add3ef">
<tr bgcolor="#eff3ff" >
<td>使用者:{counent_user} 標題:{counent_title} 釋出時間:{counent_lastdate}</td>
</tr>
<tr bgcolor="#fff">
<td>內容:{counent_content}</td>
</tr>
</table>
</form>
</html>