《PHP編程:php靜態(tài)文件生成類實(shí)例分析》要點(diǎn):
本文介紹了PHP編程:php靜態(tài)文件生成類實(shí)例分析,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP編程本文實(shí)例講述了php靜態(tài)文件生成類.分享給大家供大家參考.
PHP編程具體實(shí)現(xiàn)辦法如下:
代碼如下:
defined('phpjb51') or die(header("http/1.1 403 not forbidden"));
??????????
class include_createstatic????????????
{???????????
???????????????
??? private $htmlpath = '';???????????
??? private $path = '';???????????
??? public $monthpath = '';???????????
??? private $listpath = '';???????????
??? private $content = '';???????????
??? private $filename = '';???????????
??? private $extname = '.html';???????????
???????????????
??? public function createhtml($type,$desname,$content)???????????
??? {???????????
??????? $this->htmlpath = getappinf('htmlpath');???????????
??????? if (!file_exists($this->htmlpath))???????????
??????? {???????????
??????????? @mkdir($this->htmlpath);???????????
??????? }???????????
??????? $this->path = $this->htmlpath.$this->monthpath.'/';???????????
??????? if (!file_exists($this->path))???????????
??????? {???????????
??????????? @mkdir($this->path);???????????
??????? }???????????
??????? $this->listpath = $this->htmlpath.'list/';???????????
??????? if (!file_exists($this->listpath))???????????
??????? {???????????
??????????? @mkdir($this->listpath);???????????
??????? }???????????
??????? switch ($type)???????????
??????? {???????????
??????????? case 'index':???????????
??????????????? $this->filename = $desname;???????????
??????????????? break;???????????
??????????? case 'list':???????????
??????????????? $this->filename = $this->listpath.$desname;???????????
??????????????? break;???????????
??????????? case 'view':???????????
??????????????? $this->filename = $this->path.$desname;???????????
??????????????? break;???????????
??????? }???????????
??????? $this->filename .= $this->extname;???????????
??????? $this->content = $content;???????????
??? }???????????
???????????????
??? public function write()???????????
??? {???????????
??????? $fp=fopen($this->filename,'wb');???????????
??????? if (!is_writable($this->filename))???????????
??????? {???????????
??????????? return false;???????????
??????? }???????????
??????? if (!fwrite($fp,$this->content))???????????
??????? {???????????
??????????? return false;???????????
??????? }???????????
??????? fclose($fp);???????????
??????? return $this->filename;???????????
??? }???????????
}?????
//辦法二
if(file_exists("./index.htm"))//看靜態(tài)index.htm文件是否存在
{
$time=time();
//文件修改時(shí)間和現(xiàn)在時(shí)間相差?的話,直接導(dǎo)向htm文件,否則重新生成htm
if(time-filemtime("./index.htm")< 600)
{
header("location:classhtml/main.htm");
}
}
//在你的開始處加入ob_start();
ob_start();
//首頁內(nèi)容,就是你的動態(tài)部分了
//在結(jié)尾加入ob_end_clean(),并把本頁輸出到一個(gè)變量中
$temp=ob_get_contents();
ob_end_clean();
//寫入文件
$fp=fopen("./index.htm",'w');
fwrite(fp,temp) or die('寫文件錯(cuò)誤');
//echo"生成html完成!";
PHP編程希望本文所述對大家的php程序設(shè)計(jì)有所幫助.
《PHP編程:php靜態(tài)文件生成類實(shí)例分析》是否對您有啟發(fā),歡迎查看更多與《PHP編程:php靜態(tài)文件生成類實(shí)例分析》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/12846.html