php静态文件生成类实例分析
2015-01-24信息快讯网
这篇文章主要介绍了php静态文件生成类,以实例形式较为详细的分析了使用php生成静态文件的方法及使用技巧,需要的朋友可以参考下
本文实例讲述了php静态文件生成类。分享给大家供大家参考。
具体实现方法如下:
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"))//看静态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使用正则表达式获取图片url的方法
php使用CURL伪造IP和来源实例详解
php+mysql实现无限分类实例详解
php截取html字符串及自动补全html标签的方法
php在linux下检测mysql同步状态的方法
php导入excel文件到mysql数据库的方法
PHP上传文件时自动分配路径的方法
PHP中使用SimpleXML检查XML文件结构实例
php静态文件返回304技巧分享
php使用fputcsv()函数csv文件读写数据的方法
phplot生成图片类用法详解
php+mysql实现用户注册登陆的方法
php采集内容中带有图片地址的远程图片并保存的方法
php中socket通信机制实例详解
php读取csv数据保存到数组的方法
php获取用户浏览器版本的方法
php堆排序实现原理与应用方法
PHP实现格式化文件数据大小显示的方法
php将文本文件转换csv输出的方法
php在线解压ZIP文件的方法
discuz目录文件资料汇总
php生成excel列名超过26列大于Z时的解决方法
php+jQuery.uploadify实现文件上传教程
thinkphp3.2.2实现生成多张缩略图的方法
php生成二维码时出现中文乱码的解决方法
php可生成缩略图的文件上传类实例
php实现按指定大小等比缩放生成上传图片缩略图的方法