• 技术文章 >php教程 >PHP源码

    php 生成html静态文件类程序与实例使用方法

    2016-06-08 17:27:52原创491

    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')


    function setvar($nametype='name',$dirtype='year',$rootdir='html')


    function createdir($dir='')
    {
    $this->dir=$dir?$dir:$this->dir;

    if (!is_dir($this->dir))
    {
    $temp = explode('//m.sbmmt.com/m/',$this->dir);
    $cur_dir = '';
    for($i=0;$i {
    $cur_dir .= $temp[$i].'//m.sbmmt.com/m/';
    if (!is_dir($cur_dir))

    }
    }
    }

    function getdir($dirname='',$time=0)
    {
    $this->time=$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.'//m.sbmmt.com/m/'.$this->dirname;
    break;
    case 'year':
    $this->dir=$this->rootdir.'//m.sbmmt.com/m/'.date("Y",$this->time);
    break;

    case 'month':
    $this->dir=$this->rootdir.'//m.sbmmt.com/m/'.date("Y-m",$this->time);
    break;

    case 'day':
    $this->dir=$this->rootdir.'//m.sbmmt.com/m/'.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];
    }

    case 'nametime':
    $this->name=$this->dir.'//m.sbmmt.com/m/'.$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.'//m.sbmmt.com/m/'.$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)))

    closedir($handle);
    rmdir($file);
    return true;
    }else
    }
    }

    }
    ?>

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:this gt dirname quot time
    上一篇:dedecms 高级搜索功能函数 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 费了点心思写的Php图像处理类• 用PHP MySQL进行分页的详细说明(二)• PHP读取文本文件并逐行输出该行使用最多的字符串及对应次数• PHP实现301跳转,及延时跳转代码• 高亮显示搜索结果代码
    1/1

    PHP中文网