程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 用PHP生成靜態HTML速度快類庫

用PHP生成靜態HTML速度快類庫

編輯:PHP綜合

復制代碼 代碼如下:
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: [email protected]
// MSN: [email protected]
// 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: [email protected]
// MSN: [email protected]
// 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: [email protected]
// MSN: [email protected]
// 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處理尾
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved