程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 靜態文件生成類

php 靜態文件生成類

編輯:關於PHP編程

php教程 靜態文件生成類
defined('php教程ox') 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"))//看靜態index.htm文件是否存在
{
$time=time();
//文件修改時間和現在時間相差?的話,直接導向htm文件,否則重新生成htm
if(time-filemtime("./index.htm")< 600)
{
header("location:classhtml/main.htm");
}
}
//在你的開始處加入ob_start();
ob_start();
//首頁內容,就是你的動態部分了
//在結尾加入ob_end_clean(),並把本頁輸出到一個變量中
$temp=ob_get_contents();
ob_end_clean();
//寫入文件
$fp=fopen("./index.htm",'w');
fwrite(fp,temp) or die('寫文件錯誤');
//echo"生成html完成!";


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved