Copy Code code as follows:
<?php
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 = "";
}
< description >
A bound data source with an array of arguments.
</Description >
function Binddata ($arr)
{
$this->datasource = $arr;
}
< description >
Sets the file storage path.
</Description >
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 <count ($PATHARR); $i + +)
{
if ($pathArr [$i]== "")
Continue
Else
if (Is_dir ($currentPath. "/" . $PATHARR [$i]))
$currentPath = $currentPath. "/" . $PATHARR [$i];
Else
mkdir ($currentPath = $currentPath. "/" . $PATHARR [$i]);
}
}
< description >
Generate a static file.
</Description >
function Create ()
{
$tmp = $this->templet;
foreach ($this->datasource as $key => $value)
{
$tmp = Str_replace ("<field_". $key. ">", $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;
}
?>