您好,欢迎访问一九零五行业门户网

php 生成静态HTML页面最简单的方法示例

现在很多网站系统,如dedecms、phpcms、帝国等知名内容管理系统都提供生成静态页面的功能,这不光有利于搜索引擎的抓取,而且还能有效降低服务器压力。对于学习php,将要从事web网站开发的朋友们来说,了解这个功能是必须的,这篇文章主要介绍了php生成静态html页面最简单方法示例,本文使用模板替换的方法生成html页面,是最通用的方法,需要的朋友可以参考下
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>
以上就是php 生成静态html页面最简单的方法示例的详细内容。
其它类似信息

推荐信息