PHP靜態(tài)文件生成類實例
更新時間:2014年11月29日 15:07:43 投稿:shichen2014
這篇文章主要介紹了PHP靜態(tài)文件生成類,以實例形式演示了PHP生成靜態(tài)文件的方法,并封裝成類文件便于使用,是非常實用的技巧,需要的朋友可以參考下
本文實例講述了PHP靜態(tài)文件生成類。分享給大家供大家參考。
具體實現(xiàn)代碼如下:
復(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 '沒有這個目錄'.$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();
}
}
?>
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();
}
}
?>
具體用法如下:
復(fù)制代碼 代碼如下:
<?php
$s=new CreateHtml();
$s->start();
?>
<html>
<body>
asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
adfasdfasdf<br>
</body>>
</html>
<?php
$s->end();
?>
$s=new CreateHtml();
$s->start();
?>
<html>
<body>
asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
adfasdfasdf<br>
</body>>
</html>
<?php
$s->end();
?>
希望本文所述對大家的PHP程序設(shè)計有所幫助。
相關(guān)文章
php curl獲取https頁面內(nèi)容,不直接輸出返回結(jié)果的設(shè)置方法
今天小編就為大家分享一篇php curl獲取https頁面內(nèi)容,不直接輸出返回結(jié)果的設(shè)置方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01PHP基于MySQLI函數(shù)封裝的數(shù)據(jù)庫連接工具類【定義與用法】
這篇文章主要介紹了PHP基于MySQLI函數(shù)封裝的數(shù)據(jù)庫連接工具類,結(jié)合實例形式分析了php封裝mysqli函數(shù)實現(xiàn)的數(shù)據(jù)庫操作類定義及連接、增刪改查數(shù)據(jù)庫等基本操作用法,需要的朋友可以參考下2017-08-08安裝ImageMagick出現(xiàn)error while loading shared libraries的解決方法
這篇文章主要介紹了安裝ImageMagick出現(xiàn)error while loading shared libraries的解決方法,是ImageMagick安裝與運行中經(jīng)常出現(xiàn)的問題,需要的朋友可以參考下2014-09-09PHP獲取指定函數(shù)定義在哪個文件中以及其所在的行號實例
這篇文章主要介紹了PHP獲取指定函數(shù)定義在哪個文件中以及其所在的行號實例,需要的朋友可以參考下2014-05-05ThinkPHP的RBAC(基于角色權(quán)限控制)深入解析
本篇文章是對ThinkPHP的RBAC(基于角色權(quán)限控制)進行了詳細的分析介紹,需要的朋友參考下2013-06-06