生成静态页面的PHP类


Posted in PHP onJuly 15, 2006
<?php  
class html  
{  
    var $dir;        //dir for the htmls(without/)  
    var $rootdir;    //root of html files(without/):html  
    var $name;       //html文件存放路径  
    var $dirname;    //指定的文件夹名称  
    var $url;        //获取html文件信息的来源网页地址  
    var $time;       //html文件信息填加时的时间  
    var $dirtype;    //目录存放方式:year,month,,,,  
    var $nametype;   //html文件命名方式:name      function html($nametype='name',$dirtype='year',$rootdir='html')  
    {  
        $this--->setvar($nametype,$dirtype,$rootdir);  
    }  
    function setvar($nametype='name',$dirtype='year',$rootdir='html')  
    {  
      $this->rootdir=$rootdir;  
      $this->dirtype=$dirtype;  
      $this->nametype=$nametype;  
    }  
    function createdir($dir='')  
    {  
        $this->dir=$dir?$dir:$this->dir;  
        if (!is_dir($this->dir))  
        {  
            $temp = explode('/',$this->dir);  
            $cur_dir = '';  
            for($i=0;$itime=$time?$time:$this->time;  
        $this->dirname=$dirname?$dirname:$this->dirname;  
        switch($this->dirtype)  
        {  
        case 'name':  
        if(empty($this->dirname))  
           $this->dir=$this->rootdir;  
        else  
           $this->dir=$this->rootdir.'/'.$this->dirname;  
        break;  
        case 'year':  
        $this->dir=$this->rootdir.'/'.date("Y",$this->time);  
        break;  
        case 'month':  
        $this->dir=$this->rootdir.'/'.date("Y-m",$this->time);  
        break;  
        case 'day':  
        $this->dir=$this->rootdir.'/'.date("Y-m-d",$this->time);  
        break;  
        }  
        $this->createdir();  
        return $this->dir;  
    }  
    function geturlname($url='')  
    {  
        $this->url=$url?$url:$this->url;  
        $filename=basename($this->url);  
        $filename=explode(".",$filename);  
        return $filename[0];  
    }  
    function geturlquery($url='')  
    {  
        $this->url=$url?$url:$this->url;  
        $durl=parse_url($this->url);  
        $durl=explode("&",$durl[query]);  
        foreach($durl as $surl)  
        {  
          $gurl=explode("=",$surl);  
          $eurl[]=$gurl[1];  
        }  
        return join("_",$eurl);  
    }  
    function getname($url='',$time=0,$dirname='')  
    {  
        $this->url=$url?$url:$this->url;  
        $this->dirname=$dirname?$dirname:$this->dirname;  
        $this->time=$time?$time:$this->time;  
        $this->getdir();  
        switch($this->nametype)  
        {  
        case 'name':  
        $filename=$this->geturlname().'.htm';  
        $this->name=$this->dir.'/'.$filename;  
        break;  
        case 'time':  
        $this->name=$this->dir.'/'.$this->time.'.htm';  
        break;  
        case 'query':  
        $this->name=$this->dir.'/'.$this->geturlquery().'.htm';  
        break;  
        case 'namequery':  
        $this->name=$this->dir.'/'.$this->geturlname().'-'.$this->geturlquery().'.htm';  
        break;  
        case 'nametime':  
        $this->name=$this->dir.'/'.$this->geturlname().'-'.$this->time.'.htm';  
        break;  
        }  
        return $this->name;  
    }  
    function createhtml($url='',$time=0,$dirname='',$htmlname='')  
    {  
        $this->url=$url?$url:$this->url;  
        $this->dirname=$dirname?$dirname:$this->dirname;  
        $this->time=$time?$time:$this->time;  
      //上面保证不重复地把变量赋予该类成员  
        if(empty($htmlname))  
            $this->getname();  
        else  
            $this->name=$dirname.'/'.$htmlname;  //得到name  
        $content=file($this->url) or die("Failed to open the url ".$this->url." !");;  
///////////////关键步---用file读取$this->url  
   
        $content=join("",$content);  
        $fp=@fopen($this->name,"w") or die("Failed to open the file ".$this->name." !");  
        if(@fwrite($fp,$content))  
        return true;  
        else  
        return false;  
        fclose($fp);  
    }  
/////////////////以name为名字生成html  
    function deletehtml($url='',$time=0,$dirname='')  
    {  
        $this->url=$url?$url:$this->url;  
        $this->time=$time?$time:$this->time;  
        $this->getname();  
        if(@unlink($this->name))  
        return true;  
        else  
        return false;  
    }  
    /**  
     * function::deletedir()  
     * 删除目录  
     * @param $file 目录名(不带/)  
     * @return  
     */  
     function deletedir($file)  
     {  
        if(file_exists($file))  
        {  
            if(is_dir($file))  
            {  
                $handle =opendir($file);  
                while(false!==($filename=readdir($handle)))  
                {  
                    if($filename!="."&&$filename!="..")  
                      $this->deletedir($file."/".$filename);  
                }  
                closedir($handle);  
                rmdir($file);  
                return true;  
            }else{  
                unlink($file);  
            }  
        }  
    }  
}  
?>

 

PHP 相关文章推荐
对Session和Cookie的区分与解释
Mar 16 PHP
解析PHP生成静态html文件的三种方法
Jun 18 PHP
解析在apache里面给php写虚拟目录的详细方法
Jun 24 PHP
PHP jQuery表单,带验证具体实现方法
Feb 15 PHP
高性能PHP框架Symfony2经典入门教程
Jul 08 PHP
PHP中使用break跳出多重循环代码实例
Jan 21 PHP
php中curl使用指南
Feb 05 PHP
简单了解将WordPress中的工具栏移到底部的小技巧
Dec 31 PHP
PHP实践教程之过滤、验证、转义与密码详解
Jul 24 PHP
微信接口生成带参数的二维码
Jul 31 PHP
总结PHP代码规范、流程规范、git规范
Jun 18 PHP
laravel框架中视图的基本使用方法分析
Nov 23 PHP
删除无限级目录与文件代码共享
Jul 12 #PHP
PHP截取中文字符串的问题
Jul 12 #PHP
最令PHP初学者头痛的十四个问题
Jul 12 #PHP
WinXP + Apache +PHP5 + MySQL + phpMyAdmin安装全功略
Jul 09 #PHP
PHP初学者头疼问题总结
Jul 08 #PHP
php分页函数
Jul 08 #PHP
从零开始 教你如何搭建Discuz!4.1论坛
Jul 07 #PHP
You might like
php中的静态变量的基本用法
2014/03/20 PHP
PHP使用缓存即时输出内容(output buffering)的方法
2015/08/03 PHP
php图片添加水印例子
2016/07/20 PHP
基于PHP的微信公众号的开发流程详解
2020/08/07 PHP
js获取事件源及触发该事件的对象
2013/10/24 Javascript
Jquery中扩展方法extend使用技巧
2014/08/24 Javascript
javascript中cookie对象用法实例分析
2015/01/30 Javascript
javascript中typeof操作符和constucor属性检测
2015/02/26 Javascript
jQuery Ajax调用WCF服务详细教程
2015/03/31 Javascript
浅谈jQuery 中的事件冒泡和阻止默认行为
2016/05/28 Javascript
针对BootStrap中tabs控件的美化和完善(推荐)
2016/07/06 Javascript
jquery对Json的各种遍历方法总结(必看篇)
2016/09/29 Javascript
基于BootStrap与jQuery.validate实现表单提交校验功能
2016/12/22 Javascript
详解JS异步加载的三种方式
2017/03/07 Javascript
Bootstrap实现下拉菜单多级联动
2017/11/23 Javascript
javascript History对象原理解析
2020/02/17 Javascript
vue表单验证之禁止input输入框输入空格
2020/12/03 Vue.js
JavaScript中条件语句的优化技巧总结
2020/12/04 Javascript
vue 通过base64实现图片下载功能
2020/12/19 Vue.js
[06:40]2014DOTA2西雅图国际邀请赛 DK战队巡礼
2014/07/07 DOTA
Python加密方法小结【md5,base64,sha1】
2017/07/13 Python
pygame游戏之旅 添加游戏暂停功能
2018/11/21 Python
Django框架用户注销功能实现方法分析
2019/05/28 Python
详解Python self 参数
2019/08/30 Python
python tornado修改log输出方式
2019/11/18 Python
深入了解Python装饰器的高级用法
2020/08/13 Python
css3实现画半圆弧线的示例代码
2017/11/06 HTML / CSS
森海塞尔美国官网:Sennheiser耳机与耳麦
2017/07/19 全球购物
澳大利亚儿童和婴儿产品在线商店:Lime Tree Kids
2017/10/05 全球购物
澳大利亚排名第一的在线酒类商店:MyBottleShop
2018/04/26 全球购物
P D PAOLA法国官网:西班牙著名的珠宝首饰品牌
2020/02/15 全球购物
2019年Java 最常见的 面试题
2016/10/19 面试题
什么是SQL Server的确定性函数和不确定性函数
2016/08/04 面试题
材料加工硕士生求职信
2013/10/10 职场文书
2014最新开业庆典策划方案(5篇)
2014/09/15 职场文书
2014年人民警察入党思想汇报
2014/10/12 职场文书