网页静态化方法有很多,本文为大家介绍的是PHP下使用模板生成静态页面。当然只是一个非常简单的例子,因为我一直觉得,学习的例子越是简单,越有利于说清楚问题与学习。
先来看模板文件templets.htm:
<html>
<head>
<title>{title}</title>
</head>
<body>
<p>Hello {hello}</p>
</body>
</html>
再来看以下PHP程序,直接调用以上模版文件,进行生成静态网页。
<?php
$title='Webjx';
$hello='webjxcom!';
$file=file_get_contents('templets.htm');
$file=str_replace(array('{title}','{hello}'),array($title,$hello),$file);
echo$file;
?>

