Code kopieren Der Code lautet wie folgt:
class html
{
var $dir; //dir für die HTMLs (ohne/)
var $rootdir; :html
var $name; //HTML-Dateispeicherpfad
var $dirname; //Angegebener Ordnername
var $url; //Quelle zum Abrufen der HTML-Dateiinformationen Adresse
var $time; //Zeit zum Ausfüllen der HTML-Dateiinformationen
var $dirtype; //Verzeichnisspeichermethode: Jahr, Monat,,,,
var $nametype; //HTML-Dateibenennung Methode: Name
Funktion html($nametype='name',$dirtype='year',$rootdir='html')
{
setvar($nametype ,$dirtype,$rootdir );
}
function setvar($nametype='name',$dirtype='year',$rootdir='html')
{ this->rootdir=$rootdir
$this->dirtype=$dirtype;
$this->nametype=$nametype; ='')
{
$this->dir=$dir?$dir:$ this- & gt; Dir; $cur_dir,0777); 🎜> 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->d ir=$ this->rootdir; else $this->dir=$this-> ;rootdir.'/'.$this->dirname;
case 'year' :
$this->dir=$this->rootdir.'/'.date( "Y",$this->time);
brechen;
case 'month':
$this->dir=$this->rootdir.'/'.date("Y-m",$this->time);
Pause;
case 'day':
$this->dir=$this->rootdir.'/'.date("Y-m-d",$this->time);
Pause;
}
$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;
Pause;
case 'time':
$this->name=$this->dir.'/'.$this->time.'.htm';
Pause;
case 'query':
$this->name=$this->dir.'/'.$this->geturlquery().'.htm';
Pause;
case 'namequery':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this-> geturlquery().'.htm';
Pause;
case 'nametime':
$this->name=$this->dir.'/'.$this->geturlname().'-'.$this-> Zeit.'.htm';
Pause;
}
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("Die URL konnte nicht geöffnet werden.".$this->url." !");;
//////////////关键步---用file读取$this->url
$content=join( "",$content);
$fp=@fopen($this->name,"w") or die("Die Datei konnte nicht geöffnet werden.".$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()
* Verzeichnis löschen
* @param $file Verzeichnisname (ohne /)
* @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);
}
}
}
}
?>
Das obige ist der detaillierte Inhalt vonGenerieren Sie eine statische Seite PHP-Klasse_PHP-Programmierung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!