最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2012年07月17日 09:51:28   作者:  
最近需要將自己寫(xiě)的php文件生成靜態(tài),經(jīng)過(guò)查找,發(fā)現(xiàn)有多種方法,不同需求可以選擇不同的方法
第一種:將php動(dòng)態(tài)頁(yè)面內(nèi)容生成靜態(tài)
復(fù)制代碼 代碼如下:

ob_start();#開(kāi)啟服務(wù)器緩存
include_once 'Index.php';
$ctx=ob_get_contents();#獲取緩存
ob_end_clean();#清空緩存
$fh=fopen("index.html","w+");
fwrite($fh,$ctx);#寫(xiě)入html,生成html
fclose($fh);
/*
1、Flush:刷新緩沖區(qū)的內(nèi)容,輸出。
函數(shù)格式:flush()
說(shuō)明:這個(gè)函數(shù)經(jīng)常使用,效率很高。
2、ob_start :打開(kāi)輸出緩沖區(qū)
函數(shù)格式:void ob_start(void)
說(shuō)明:當(dāng)緩沖區(qū)激活時(shí),所有來(lái)自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)
說(shuō)明:這個(gè)函數(shù)會(huì)返回當(dāng)前緩沖區(qū)中的內(nèi)容,如果輸出緩沖區(qū)沒(méi)有激活,則返回 FALSE 。
4、ob_get_length:返回內(nèi)部緩沖區(qū)的長(zhǎng)度。
使用方法:int ob_get_length(void)
說(shuō)明:這個(gè)函數(shù)會(huì)返回當(dāng)前緩沖區(qū)中的長(zhǎng)度;和ob_get_contents一樣,如果輸出緩沖區(qū)沒(méi)有激活。則返回 FALSE。
5、ob_end_flush :發(fā)送內(nèi)部緩沖區(qū)的內(nèi)容到瀏覽器,并且關(guān)閉輸出緩沖區(qū)。
使用方法:void ob_end_flush(void)
說(shuō)明:這個(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)
說(shuō)明:這個(gè)函數(shù)不會(huì)輸出內(nèi)部緩沖區(qū)的內(nèi)容而是把它刪除!
7、ob_implicit_flush:打開(kāi)或關(guān)閉絕對(duì)刷新
使用方法:void ob_implicit_flush ([int flag])
*/

第二種:
php 靜態(tài)文件生成類(lè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 '沒(méi)有這個(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();
?>

相關(guān)文章

最新評(píng)論

青州市| 尉犁县| 青川县| 宜兰市| 大宁县| 武功县| 天全县| 沛县| 通榆县| 信丰县| 宁武县| 双鸭山市| 武安市| 茶陵县| 葵青区| 利辛县| 龙川县| 察哈| 嘉兴市| 巴中市| 稻城县| 浮山县| 塔城市| 永嘉县| 白沙| 东光县| 四子王旗| 东平县| 绥滨县| 宝兴县| 梅河口市| 崇义县| 临江市| 兴安盟| 彭水| 肥城市| 怀来县| 赤水市| 承德县| 杭州市| 元阳县|