国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > PHP > 正文

php靜態(tài)文件生成類實(shí)例分析

2024-05-04 21:55:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 這篇文章主要介紹了php靜態(tài)文件生成類,以實(shí)例形式較為詳細(xì)的分析了使用php生成靜態(tài)文件的方法及使用技巧,需要的朋友可以參考下

  

本文實(shí)例講述了php靜態(tài)文件生成類。分享給大家供大家參考。

具體實(shí)現(xiàn)方法如下:


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();
//首頁(yè)內(nèi)容,就是你的動(dòng)態(tài)部分了
//在結(jié)尾加入ob_end_clean(),并把本頁(yè)輸出到一個(gè)變量中
$temp=ob_get_contents();
ob_end_clean();
//寫入文件
$fp=fopen("./index.htm",'w');
fwrite(fp,temp) or die('寫文件錯(cuò)誤');
//echo"生成html完成!";

 

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 岚皋县| 博乐市| 天柱县| 香格里拉县| 喀什市| 色达县| 六枝特区| 宜都市| 招远市| 曲靖市| 措美县| 军事| 定州市| 高淳县| 象州县| 内江市| 长武县| 汾阳市| 博湖县| 仪征市| 古交市| 仪陇县| 崇礼县| 永吉县| 平南县| 手游| 黎城县| 石渠县| 高要市| 郁南县| 岚皋县| 赤壁市| 利川市| 沾化县| 恩平市| 榆社县| 巴林左旗| 甘洛县| 夹江县| 大新县| 平顶山市|