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

首頁 > 編程 > PHP > 正文

php靜態文件生成類實例分析

2020-03-22 19:44:36
字體:
來源:轉載
供稿:網友
本文實例講述了php靜態文件生成類。分享給大家供大家參考。具體實現方法如下:
復制代碼 代碼如下:defined('phpphpstudy') or die(header("http/1.1 403 not forbidden"));

html' target='_blank'>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完成!";希望本文所述對大家的php程序設計有所幫助。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹿泉市| 菏泽市| 平凉市| 武宁县| 明光市| 沾化县| 舞钢市| 封开县| 句容市| 榆中县| 焦作市| 岢岚县| 遵义市| 南丹县| 西青区| 望江县| 广西| 陆良县| 八宿县| 佛山市| 南京市| 博罗县| 蛟河市| 河西区| 琼海市| 乌兰察布市| 夏邑县| 乐亭县| 抚顺县| 突泉县| 广饶县| 光山县| 石柱| 手机| 湘西| 和龙市| 浦江县| 手游| 沭阳县| 开平市| 沅江市|