PHP Tutorial Generate HTML static file class program and instance use method
Class HTML
{
var $dir; Dir for the htmls (without/)
var $rootdir; Root of HTML files (without/): HTML
var $name; HTML File Store path
var $dirname; Specified folder name
var $url; Gets the source page address of the HTML file information
var $time; HTML file information fill in overtime
var $dirtype; Directory Storage mode: Year,month,,,,
var $nametype; HTML file naming method: 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 ('/', $this->dir);
$cur _dir = ';
for ($i =0; $i {
$cur _dir. = $temp [$i]. /';
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. /'. $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];
}
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;
This ensures that the variable is not repeatedly assigned to the class member
if (empty ($htmlname))
$this->getname ();
Else
$this->name= $dirname. ' /'. $htmlname; Get Name
$content =file ($this->url) or Die ("Failed to open the URL". $this->url. ");;
Key Step---read $this->url with file
$content =join ("", $content);
$fp = @fopen ($this->name, "w") or Die ("Failed to open" file. $this->name. ");
if (@fwrite ($FP, $content))
return true;
Else
return false;
Fclose ($FP);
}
Generate HTML with Name
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::d eletedir ()
* 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))
Closedir ($handle);
RmDir ($file);
return true;
}else
}
}
}
?>