色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php生成靜態文件的多種方法分享

第一種:將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 靜態文件生成類(自家用)
復制代碼 代碼如下:
<?php
class CreateHtml
{
function mkdir( $prefix= 'article' )
{
$y = date('Y');
$m = date('m');
$d = date('d');
$p=DIRECTORY_SEPARATOR;
$filePath='article'.$p.$y.$p.$m.$p.$d;
$a=explode($p,$filePath);
foreach ( $a as $dir)
{
$path.=$dir.$p;
if(!is_dir($path))
{
//echo '沒有這個目錄'.$path;
mkdir($path,0755);
}
}
return $filePath.$p;
}
function start()
{
ob_start();
}
function end()
{
$info = ob_get_contents();
$fileId = '12345';
$postfix = '.html';
$path = $this->mkdir($prefix= 'article');
$fileName = time().'_'.$fileId.$postfix;
$file=fopen($path.$fileName,'w+');
fwrite($file,$info);
fclose($file);
ob_end_flush();
}
}
?>
<?php
$s=new CreateHtml();
$s->start();
?>
<html>
<body>
asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
adfasdfasdf<br>
</body>>
</html>
<?php
$s->end();
?>

php技術php生成靜態文件的多種方法分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 雅江县| 五常市| 教育| 谢通门县| 金堂县| 九龙县| 泰来县| 喀什市| 威海市| 黄平县| 元谋县| 岑巩县| 井研县| 蒙阴县| 荃湾区| 达日县| 海晏县| 亚东县| 福清市| 尼木县| 兴和县| 高密市| 三原县| 德惠市| 禹城市| 惠来县| 仪陇县| 延长县| 景谷| 津南区| 靖宇县| 松溪县| 庆安县| 滨海县| 金塔县| 伊川县| 宝山区| 明水县| 岑巩县| 合水县| 财经|