php靜態(tài)文件生成類(lèi)實(shí)例分析_PHP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法這篇文章主要介紹了php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法,可實(shí)現(xiàn)采集并保存遠(yuǎn)程圖片的功能,是非常實(shí)用的技巧,需要的朋友可以參考下 本文實(shí)例講述了php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 代碼如下:f
這篇文章主要介紹了php靜態(tài)文件生成類(lèi),以實(shí)例形式較為詳細(xì)的分析了使用php生成靜態(tài)文件的方法及使用技巧,需要的朋友可以參考下
本文實(shí)例講述了php靜態(tài)文件生成類(lèi)。分享給大家供大家參考。
具體實(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");
}
}
//在你的開(kāi)始處加入ob_start();
ob_start();
//首頁(yè)內(nèi)容,就是你的動(dòng)態(tài)部分了
//在結(jié)尾加入ob_end_clean(),并把本頁(yè)輸出到一個(gè)變量中
$temp=ob_get_contents();
ob_end_clean();
//寫(xiě)入文件
$fp=fopen("./index.htm",'w');
fwrite(fp,temp) or die('寫(xiě)文件錯(cuò)誤');
//echo"生成html完成!";
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
分享:php中socket通信機(jī)制實(shí)例詳解這篇文章主要介紹了php中socket通信機(jī)制,講述了socket通信機(jī)制的原理,并以實(shí)例形式較為詳細(xì)的分析了socket通信機(jī)制的用法,需要的朋友可以參考下 本文實(shí)例講述了php中socket通信機(jī)制及用法。分享給大家供大家參考。具體分析如下: 一、socket是什么 什么是socket 所謂so
相關(guān)PHP教程:
- php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法
- php中socket通信機(jī)制實(shí)例詳解
- php讀取csv數(shù)據(jù)保存到數(shù)組的方法
- php獲取用戶(hù)瀏覽器版本的方法
- php堆排序?qū)崿F(xiàn)原理與應(yīng)用方法
- php購(gòu)物車(chē)實(shí)現(xiàn)方法
- PHP實(shí)現(xiàn)格式化文件數(shù)據(jù)大小顯示的方法
- php自定義加密與解密程序?qū)嵗?/a>
- php使用google地圖應(yīng)用實(shí)例
- php將文本文件轉(zhuǎn)換csv輸出的方法
- 19個(gè)Android常用工具類(lèi)匯總
- php+ajax實(shí)現(xiàn)文章自動(dòng)保存的方法
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 創(chuàng)建XML Http Request對(duì)象兩個(gè)的方法
- Laravel 5 學(xué)習(xí)筆記
- Zend Framework 入門(mén)——頁(yè)面布局
- PHP獲取漢字的拼音(全部與首字母)
- 用DBSQL類(lèi)加快開(kāi)發(fā)MySQL數(shù)據(jù)庫(kù)程序的速度
- 《PHP設(shè)計(jì)模式介紹》關(guān)于本書(shū)說(shuō)明
- php截取中文字符串函數(shù)實(shí)例
- 網(wǎng)頁(yè)實(shí)例:詳細(xì)介紹用PHP來(lái)編寫(xiě)網(wǎng)頁(yè)記數(shù)器
- PHP與Javascript的兩種交互方式
- PHP教程:PHP編碼書(shū)寫(xiě)規(guī)范
- 相關(guān)鏈接:
- 教程說(shuō)明:
PHP教程-php靜態(tài)文件生成類(lèi)實(shí)例分析
。