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

php生成靜態(tài)文件的多種方法分享

第一種:將php動(dòng)態(tài)頁面內(nèi)容生成靜態(tài)
復(fù)制代碼 代碼如下:
ob_start();#開啟服務(wù)器緩存
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:刷新緩沖區(qū)的內(nèi)容,輸出。
函數(shù)格式:flush()
說明:這個(gè)函數(shù)經(jīng)常使用,效率很高。
2、ob_start :打開輸出緩沖區(qū)
函數(shù)格式:void ob_start(void)
說明:當(dāng)緩沖區(qū)激活時(shí),所有來自php程序的非文件頭信息均不會(huì)發(fā)送,而是保存在內(nèi)部緩沖區(qū)。為了輸出緩沖區(qū)的內(nèi)容,可以使用ob_end_flush()或flush()輸出緩沖區(qū)的內(nèi)容。
3 、ob_get_contents :返回內(nèi)部緩沖區(qū)的內(nèi)容。
使用
函數(shù)格式:string ob_get_contents(void)
說明:這個(gè)函數(shù)會(huì)返回當(dāng)前緩沖區(qū)中的內(nèi)容,如果輸出緩沖區(qū)沒有激活,則返回 FALSE 。
4、ob_get_length:返回內(nèi)部緩沖區(qū)的長度。
使用方法:int ob_get_length(void)
說明:這個(gè)函數(shù)會(huì)返回當(dāng)前緩沖區(qū)中的長度;和ob_get_contents一樣,如果輸出緩沖區(qū)沒有激活。則返回 FALSE。
5、ob_end_flush :發(fā)送內(nèi)部緩沖區(qū)的內(nèi)容到瀏覽器,并且關(guān)閉輸出緩沖區(qū)。
使用方法:void ob_end_flush(void)
說明:這個(gè)函數(shù)發(fā)送輸出緩沖區(qū)的內(nèi)容(如果有的話)。
6、ob_end_clean:刪除內(nèi)部緩沖區(qū)的內(nèi)容,并且關(guān)閉內(nèi)部緩沖區(qū)
使用方法:void ob_end_clean(void)
說明:這個(gè)函數(shù)不會(huì)輸出內(nèi)部緩沖區(qū)的內(nèi)容而是把它刪除!
7、ob_implicit_flush:打開或關(guān)閉絕對刷新
使用方法:void ob_implicit_flush ([int flag])
*/

第二種:
php 靜態(tài)文件生成類(自家用)
復(fù)制代碼 代碼如下:
<?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 '沒有這個(gè)目錄'.$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技術(shù)php生成靜態(tài)文件的多種方法分享,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 大姚县| 祥云县| 合川市| 龙海市| 连平县| 东乌珠穆沁旗| 文成县| 土默特右旗| 沾化县| 伊金霍洛旗| 婺源县| 阿克苏市| 繁峙县| 休宁县| 岗巴县| 靖边县| 闸北区| 灌南县| 津市市| 柘城县| 株洲市| 灵山县| 建水县| 时尚| 黄冈市| 独山县| 韩城市| 柳州市| 仙桃市| 隆尧县| 元朗区| 大邑县| 青阳县| 昌宁县| 肃南| 赞皇县| 正镶白旗| 鹰潭市| 大庆市| 凯里市| 丹寨县|