Copy CodeThe code is as follows: Class Shtml
{
var $Templet;
var $DataSource;
var $Dir;
var $fileName;
var $mod;
var $handle;
function Shtml ($fileName = "")
{
$this->filename= $fileName;
$this->mod= "WB";
$this->handle=false;
$this->templet = "";
$this->datasource = Array ();
$this->dir = "";
}
/// <描述> <描述>
A binding data source with an array of parameters.
///
function Binddata ($arr)
{
$this->datasource = $arr;
}
/// <描述> <描述>
Sets the file storage path.
///
function Setdir ($dir)
{
$this->dir = $dir;
}
function Setfilename ($fileName)
{
return $this->filename= $fileName;
}
function Getmod ()
{
return $this->mod;
}
function Setmod ($mod)
{
return $this->mod= $mod;
}
function Open ()
{
if (substr ($this->filename,0,1) = = "/")
$this->filename = $_server[' Document_root '). $this->filename;
if ($this->handle=fopen ($this->filename, $this->mod))
return $this->handle;
Else
return false;
}
function Close ()
{
Return fclose ($this->handle);
}
function Write ($content)
{
Return fwrite ($this->handle, $content);
}
function MkDir ($pathname)
{
$currentPath = "";
Str_replace ("\", "/", $pathname);
$PATHARR = Split ("/", $pathname);
if ($pathArr [0] = = "")//Use absolute path
{
$currentPath = $_server[' document_root ');
}
Else
{
$currentPath = $_server[' Document_root '). DirName ($_server[' php_self ');
}
for ($i =0; $i {
if ($pathArr [$i]== "")
Continue
Else
if (Is_dir ($currentPath. "/" . $PATHARR [$i])
$currentPath = $currentPath. "/" . $PATHARR [$i];
Else
mkdir ($currentPath = $currentPath. "/" . $PATHARR [$i]);
}
}
/// <描述> <描述>
Generates a static file.
///
function Create ()
{
$tmp = $this->templet;
foreach ($this->datasource as $key = $value)
{
$tmp = Str_replace (" ", $value, $tmp);
}
$this->mkdir (dirname ($this->filename));
$this->open ();
$this->write ($tmp);
$this->close ();
}
}
function createshtml ()
{
Ob_start ("callback_cteateshtml");
}
function callback_cteateshtml ($buffer)
{
$page = intval (@$_request["page"]);
$shtml = new shtml ();
$shtml->setfilename ($_server[' document_root '). DirName ($_server[' php_self ']). "/" . basename ($_server[' php_self '], ". PHP"). ($page ==0? "" : "_" . Strval ($page)). ". htm");
$shtml->templet = $buffer;
$shtml->create ();
return $buffer;
}
?>
http://www.bkjia.com/PHPjc/317057.html www.bkjia.com true http://www.bkjia.com/PHPjc/317057.html techarticle Copy the code as follows: PHP classshtml {var$templet; var$datasource; var$dir; var$filename; var$mod; var$handle; functionshtml ($ Filename= "") {$this-filename= $fileName; $this-...