用PHP生成静态HTML速度快类库


Posted in PHP onMarch 18, 2007
ob_start();#开启服务器缓存 
include_once 'Index.php'; 
$ctx=ob_get_contents();# 获取缓存 
ob_end_clean();#清空缓存 
$fh=fopen("index.html","w+"); 
fwrite($fh,$ctx);# 写入html,生成html 
fclose($fh);

1、Flush:刷新缓冲区的内容,输出。
函数格式:flush()
说明:这个函数经常使用,效率很高。
2、ob_start :打开输出缓冲区
函数格式:void ob_start(void)
说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在内部缓冲区。为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。
3 、ob_get_contents :返回内部缓冲区的内容。
使用
函数格式:string ob_get_contents(void)
说明:这个函数会返回当前缓冲区中的内容,如果输出缓冲区没有激活,则返回 FALSE 。
4、 ob_get_length:返回内部缓冲区的长度。
使用方法:int ob_get_length(void)
说明:这个函数会返回当前缓冲区中的长度;和ob_get_contents一样,如果输出缓冲区没有激活。则返回 FALSE。
5、ob_end_flush :发送内部缓冲区的内容到浏览器,并且关闭输出缓冲区。
使用方法:void ob_end_flush(void)
说明:这个函数发送输出缓冲区的内容(如果有的话)。
6、ob_end_clean:删除内部缓冲区的内容,并且关闭内部缓冲区
使用方法:void ob_end_clean(void)
说明:这个函数不会输出内部缓冲区的内容而是把它删除!
7、ob_implicit_flush:打开或关闭绝对刷新
使用方法:void ob_implicit_flush ([int flag])
<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// Module Name: woods-bhtml.php 
// Abstract: 生成静态HTML处理程序尾底 
// Version: 2.0 
// Date 1006-11-25 
// Author: woods·zhang 
// Website: http://www.hoojar.com/ 
// Email: hoojar@53.com 
// MSN: hoojar@hotmail.com 
// Copyright 1001-1006, Hoojar studio All Rights Reserved 
// 
// 版权 1001-1006,慧佳工作室所有版权保护 //The software for free software, allowing use, copy, 
//modify and distribute the software and files. Any 
//use of this software must place a copy of all the 
//above copyright notice. By the software Huijia studio 
//maintenance, if you have any queries please contact us. 
//Thank you. 
// 
//此软件为自由软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
//此文件只能加载在程序的最尾 
/*________________生成HTML文件______________________beign________________________________*/ 
if ($make_html) 
{ 
$buffer = ob_get_flush(); 
if ($go_html)//是否直接转到HTML文件显示还是PHP读得内容输出(0:php读内容输出1:直接转) 
{ 
/*__________处理因生成了HTML文件而产生的种径问题____________________begin_______________*/ 
$search = array( 
"/(src=|action=|href=|ajaxRead\()\"/ie", 
"/\.\.\./e", 
"/\.\/\./e", 
"/\.\.\/http:\/\//ies", 
"/\.\.\/#/", 
"/\'\.\'/e", 
"/\.\.\/javascript:/ies"); 
$replace = array( 
"'\\1\"../'", 
"'..'", 
"'.'", 
"'http://'", 
"#", 
"'\'..\''", 
"'javascript:'"); 
$buffer = preg_replace($search, $replace, $buffer); 
/*__________处理因生成了HTML文件而产生的种径问题____________________end_______________*/ 
} 
$fp = fopen(HTML_FILE, "w"); 
if ($fp) 
{ 
fwrite($fp, $buffer); 
fclose($fp); 
} 
} 
/*________________生成HTML文件______________________beign________________________________*/ 
?> 
<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// Module Name: woods-thtml.php 
// Abstract: 生成静态HTML处理程序头 
// Version: 2.0 
// Date 1006-11-25 
// Author: woods·zhang 
// Website: http://www.hoojar.com/ 
// Email: hoojar@53.com 
// MSN: hoojar@hotmail.com 
// Copyright 1001-1006, Hoojar studio All Rights Reserved 
// 
// 版权 1001-1006,慧佳工作室所有版权保护 
//The software for free software, allowing use, copy, 
//modify and distribute the software and files. Any 
//use of this software must place a copy of all the 
//above copyright notice. By the software Huijia studio 
//maintenance, if you have any queries please contact us. 
//Thank you. 
// 
//此软件为自由软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
//此文件只能加载在程序的开头 
ob_start(); 
/*___________判断是否已生成了HTML文件,若生成了则跳转到HTML页面___________begin__________*/ 
$qstring = isset($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : ""; 
if ($qstring)//程序加了GET请求的处理 
{ 
$qstring = str_replace("=", "", $qstring); 
define("HTML_FILE", "./h/{$efilename}-{$qstring}.html"); 
} 
else 
{ 
define("HTML_FILE", "./h/{$efilename}.html"); 
} 
if (file_exists(HTML_FILE)) 
{ 
$lcft = filemtime(HTML_FILE);//last create file time 
if (($lcft + 3600) > time())//判断上次生成HTML文件是否以过去1时间,若没有才直接输出文件内容 
{ 
if ($show_html)//是否以HTML静态页面展示(0不以HTML展显1以html展显) 
{ 
if ($go_html)//是否直接转到HTML文件显示还是PHP读得内容输出(0:php读内容输出1:直接转) 
{ 
header("Location: " . HTML_FILE);//直接转 
} 
else 
{ 
echo(file_get_contents(HTML_FILE));//读出展显 
} 
exit(0); 
} 
} 
} 
/*___________判断是否已生成了HTML文件,若生成了则跳转到HTML页面___________end__________*/ 
?> 
<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// Module Name: index.php 
// Abstract: 首页信息 
// Version: 1.0 
// Date 2006-11-7 
// Author: woods·zhang 
// Website: http://www.hoojar.com/ 
// Cemail: hoojar@163.com 
// MSN: hoojar@hotmail.com 
// Copyright 2001-2006, Hoojar studio All Rights Reserved 
// 
// 版权 2001-2006,慧佳工作室所有版权保护 
//The software for free software, allowing use, copy, 
//modify and distribute the software and files. Any 
//use of this software must place a copy of all the 
//above copyright notice. By the software Huijia studio 
//maintenance, if you have any queries please contact us. 
//Thank you. 
// 
//此软件为自由软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
require("woods-thtml.php");//生成HTML处理头 
//if (count($_GET) < 1 && count($_POST) < 1){require("woods-thtml.php");}//生成HTML处理头 
require("{$exec_file}");//注册语言定义文件 
foreach ($lang as $key => $value) 
{ 
$atpl[strtoupper($key) ."_LANG"] = $value; 
} 
/*____________________________________列表常识向上走的项__________________end_____________________*/ 
include("woods-templates.php"); 
$tpl = new WoodsTpl("./templates/"); 
$tpl->require_tpl("header.html"); 
$tpl->set_file(); 
$tpl->block("EBCORP", $scorp); 
$tpl->block("NEWS", $news); 
$tpl->block("PRODUCT", $product); 
$tpl->block("EBPNAME_MSG", $spname); 
$tpl->block("LORE", $lore); 
$tpl->require_tpl("footer.html"); 
$tpl->parse($atpl, true); 
$tpl = NULL; 
/*________________模板操作_________________________end___________________________________*/ 
require("woods-bhtml.php");//生成HTML处理尾 
?>
PHP 相关文章推荐
第二节 对象模型 [2]
Oct 09 PHP
综合图片计数器
Oct 09 PHP
PHP读取MySQL数据代码
Jun 05 PHP
php 上传文件类型判断函数(避免上传漏洞 )
Jun 08 PHP
PHP 读取Postgresql中的数组
Apr 14 PHP
php数据类型判断函数有哪些
Sep 23 PHP
递归删除一个节点以及该节点下的所有节点示例
Mar 19 PHP
PHP积分兑换接口实例
Feb 09 PHP
PHP获取音频文件的相关信息
Jun 22 PHP
用php和jQuery来实现“顶”和“踩”的投票功能
Oct 13 PHP
php多文件打包下载的实例代码
Jul 12 PHP
ThinkPHP实现转换数据库查询结果数据到对应类型的方法
Nov 16 PHP
PHP实现采集程序原理和简单示例代码
Mar 18 #PHP
Dedecms V3.1 生成HTML速度的优化办法
Mar 18 #PHP
dedecms模板标签代码官方参考
Mar 17 #PHP
收集的DedeCMS一些使用经验
Mar 17 #PHP
dedecms防止FCK乱格式化你的代码的修改方法
Mar 17 #PHP
dedecms采集中可以过滤多行代码的正则表达式
Mar 17 #PHP
php中文本操作的类
Mar 17 #PHP
You might like
基于ThinkPHP删除目录及目录文件函数
2020/10/28 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
2021/03/04 PHP
js获取select选中的option的text示例代码
2013/12/19 Javascript
浅析javascript中function 的 length 属性
2014/05/27 Javascript
2014 HTML5/CSS3热门动画特效TOP10
2014/12/07 Javascript
jQuery实现监控页面所有ajax请求的方法
2015/12/10 Javascript
详解jQuery uploadify文件上传插件的使用方法
2016/12/16 Javascript
微信小程序实现image组件图片自适应宽度比例显示的方法
2018/01/16 Javascript
JavaScript代码实现txt文件的上传预览功能
2018/03/27 Javascript
layui上传图片到服务器的非项目目录下的方法
2019/09/26 Javascript
整理 node-sass 安装失败的原因及解决办法(小结)
2020/02/19 Javascript
JavaScript实现轮播图特效
2020/04/10 Javascript
antd配置config-overrides.js文件的操作
2020/10/31 Javascript
微信小程序实现天气预报功能(附源码)
2020/12/10 Javascript
windows下安装python paramiko模块的代码
2013/02/10 Python
在Python中封装GObject模块进行图形化程序编程的教程
2015/04/14 Python
进一步探究Python中的正则表达式
2015/04/28 Python
Python实现单词翻译功能
2017/06/06 Python
tensorflow学习笔记之mnist的卷积神经网络实例
2018/04/15 Python
Python中实现单例模式的n种方式和原理
2018/11/14 Python
Python3+OpenCV2实现图像的几何变换(平移、镜像、缩放、旋转、仿射)
2019/05/13 Python
python利用re,bs4,requests模块获取股票数据
2019/07/29 Python
Python 类的魔法属性用法实例分析
2019/11/21 Python
python3 图片 4通道转成3通道 1通道转成3通道 图片压缩实例
2019/12/03 Python
python代码xml转txt实例
2020/03/10 Python
python实现发送QQ邮件(可加附件)
2020/12/23 Python
利用css3如何设置没有上下边的列表间隔线
2017/07/03 HTML / CSS
西尔斯百货官网:Sears
2016/09/06 全球购物
英国领先的在线旅游和休闲零售商:lastminute.com
2019/01/23 全球购物
合作意向书模板
2014/03/31 职场文书
大学生自我评价200字(4篇)
2014/09/17 职场文书
西湖英语导游词
2015/02/06 职场文书
表扬信格式模板
2015/05/05 职场文书
企业法人代表证明书
2015/06/18 职场文书
python基础之文件处理知识总结
2021/05/23 Python
高通2023 年将发布高性能PC处理器
2022/04/29 数码科技