生成静态页面一般是把动态页面生成html页面,这样可以减少服务器负载也是现在各大网站常用的优化方法,下面我来分享一个把php生成静态(html)页面类。
| 代码如下 | 复制代码 |
|
class create_html { private $template; //模版 立即学习“PHP免费学习笔记(深入)”; private $file_name; //文件名 private $array; //数据数组 function __construct($file_name, $template, $array) { //构造类 $this->template = $this->read_file($template, "r"); //读取模板文件 $this->file_name = $file_name; $this->array = $array; //数据数据 $this->html(); //生成html } function html() { //生成html while (ereg ("{([0-9]+)}", $this->template, $regs)) { //循环模版中所能的{1}….. $num = $regs[1]; //得到1、2、3序列 $this->template = ereg_replace("{".$num."}", $this->array[$num], $this->template); //把数据替换成html内容 $this->write_file($this->file_name, $this->template, "w+"); //生成HTML文件 } } function read_file($file_url, $method = "r") { //读取文件 $fp = @fopen($file_url, $method);
思远企业网站管理系统1.0
查看详情
思远企业网站管理系统是由思远负责人结合多年的开发精髓为企业量身订做的一套全国通用版本的企业网站 管理系统,该系统体积小,代码执行速度快,用户操作相当简单而深受大家的喜爱。 版本说明:程序采用asp.net(c#)+access(节约企业资源) 1:网站由后台全静态生成前台所有页面,简化操作,一键即可生成大型企业网站 2:网站栏目灵活控制:是为企业量身订做的企业网站,通过模板自由生成各行各业大型企业
0
//打开文件 $file_data = fread($fp, filesize($file_url)); //读取文件信息 return $file_data; } function write_file($file_url, $data, $method) { //写入文件 $fp = @fopen($file_url, $method); //打开文件 @flock($fp, LOCK_EX); //锁定文件 $file_data = fwrite($fp, $data); //写入文件 fclose($fp); //关闭文件 return $file_data; } } #例子———————- #读取邮件回复模版———————————————————————————- $title = "标题"; $navigation = "浏览器"; $happy_origin = "作者"; $name = "test2.htm"; $template = "default_tmp.php"; //模版中用{1}{2}来替换 $daytype = array(1 => $title, 2 => $navigation, 3 => $happy_origin); $htm = new Restore_email($template, $daytype); echo $htm->pint(); ?> | |
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号