harry potter and the deathly h PHP class to generate static pages

WBOY
Release: 2016-07-29 08:35:11
Original
882 people have browsed it

Copy the code The code is as follows:


class html
{
var $dir; //dir for the htmls(without/)
var $rootdir; //root of html files(without/):html
var $name; // html file storage path
var $dirname; //Specified folder name
var $url; //Get the source web page address of html file information
var $time; //Time to fill in html file information
var $dirtype ; //Directory storage method: year, month,,,,
var $nametype; //html file naming method: 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;$i {
$cur_dir .= $temp[$i].'/';
if (!is_dir($cur_dir))
{
@mkdir($cur_dir,0777);
}
}
}
}
function getdir($dirname='',$time=0)
{
$this-& gt ;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. '/'.$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 
 $c
///////////////关键步---用file读取$this->url 
 
 $c
 $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()
* Delete directory
* @param $file directory name (without /)
* @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); 
 } 
 } 
 } 

?>

以上就介绍了harry potter and the deathly h 生成静态页面的PHP类,包括了harry potter and the deathly h方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template