class html function html($nametype='name',$dirtype='year',$rootdir='html') function setvar($nametype='name',$dirtype='year',$rootdir='html') function createdir($dir='') if (!is_dir($this->dir)) } function getdir($dirname='',$time=0) switch($this->dirtype) case 'month': case 'day': $this->createdir(); return $this->dir; function geturlname($url='') $filename=basename($this->url); function geturlquery($url='') $durl=parse_url($this->url); return join("_",$eurl); function getname($url='',$time=0,$dirname='') $this->getdir(); switch($this->nametype) case 'time': case 'query': case 'namequery': case 'nametime': } function createhtml($url='',$time=0,$dirname='',$htmlname='') $content=file($this->url) or die("Failed to open the url ".$this->url." !");; ///////////////关键步---用file读取$this->url $content=join("",$content); function deletehtml($url='',$time=0,$dirname='') $this->getname(); if(unlink($this->name)) /** closedir($handle); }
{
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
{
$this->dir=$dir?$dir:$this->dir;
{
$temp = explode('/',$this->dir);
$cur_dir = '';
for($i=0;$i {
$cur_dir .= $temp[$i].'/';
if (!is_dir($cur_dir))
}
}
{
$this->time=$time?$time:$this->time;
$this->dirname=$dirname?$dirname:$this->dirname;
{
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;
$this->dir=$this->rootdir.'/'.date("Y-m",$this->time);
break;
$this->dir=$this->rootdir.'/'.date("Y-m-d",$this->time);
break;
}
}
{
$this->url=$url?$url:$this->url;
$filename=explode(".",$filename);
return $filename[0];
}
{
$this->url=$url?$url:$this->url;
$durl=explode("&",$durl[query]);
foreach($durl as $surl)
}
{
$this->url=$url?$url:$this->url;
$this->dirname=$dirname?$dirname:$this->dirname;
$this->time=$time?$time:$this->time;
{
case 'name':
$filename=$this->geturlname().'.htm';
$this->name=$this->dir.'/'.$filename;
break;
$this->name=$this->dir.'/'.$this->time.'.htm';
break;
$this->name=$this->dir.'/'.$this->geturlquery().'.htm';
break;
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->geturlquery().'.htm';
break;
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this->time.'.htm';
break;
return $this->name;
}
{
$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
$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
{
$this->url=$url?$url:$this->url;
$this->time=$time?$time:$this->time;
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)))
rmdir($file);
return true;
}else
}
}
?>
Web开发源代码:PHP生成静态页面的类
80酷酷网 80kuku.com