<?php
Date_default_timezone_set ("Asia/shanghai");
Class tcreatehtml{
var $HTemplate; Files for templates
var $FileName; New file name
var $HTFilePath//path to generate file
var $ModiString;
var $ReTextArray;//substitution Information array
var $strText = ""; Text content
var $CrType = "1"; The type that produces the file name defaults to the date + 4-bit random number
var $errorStr; Error message!
interface functions
Construct template
function tcreatehtml () {}
Create a file
function creatrhtml ()
{
Check that the template path is legitimate
if (! $this->checkpath ($this->htemplate, "0"))
{
return false;
}
Check to see if the new file path is legitimate
if (! $this->checkpath ($this->htfilepath, "1"))
{
return false;
}
$FP =fopen ($this->htemplate, "R"); Read-only open template
$this->strtext=fread ($fp, FileSize ($this->htemplate));//Read the contents of the template
Fclose ($FP);
Replace file
$this->replacetext ();
Generate file name
$this->createname ();
$handle =fopen ($this->filename, "w"); Write way to open a news path
Fwrite ($handle, $this->strtext); Write what you just replaced into the generated HTML file
Fclose ($handle);
return true;
}
function Checkpath ($PSTR, $type)
{
if ($type = = "0")
{
if (!file_exists ($PSTR))
{
$this->errorstr= "folder path is wrong!";
return false;
}
}else
{
$arrPath = Explode ("/", $PSTR);
$s _path= "";
foreach ($arrPath as $tag) {
if ($s _path== "")
{
$s _path. = $tag;
}else
{
$s _path. = "/". $tag;
}