Generally we use PHP to output an HTML file, always with $head= "
The class definition file createhtml.class.php is as follows:
<?php
//-------------------
Tcreatehtml
A class that generates a static HTML file from a template file
Author: sharetop
Email:ycshowtop@21cn.com
//-------------------
Define the required work functions
Convention to start with tags <!--# #name ##-->
End with Mark <!--@@-->
function Isbegin ($STR) {
$pattern = "<!--##[a-za-z]+##-->";
if (Ereg ($pattern, $STR)) return true;
return false;
}
function Isfinish ($STR) {
$pattern = "<!--@@[a-za-z]+@@-->";
if (Ereg ($pattern, $STR)) return true;
return false;
}
function GetName ($STR) {
$tmp =explode ("# #", $STR);
return $tmp [1];
}
//******************
Defining classes
Class Tcreatehtml {
var $HTemplate;
var $FileName;
var $ModiString;
interface functions
Construct template
function tcreatehtml ($tmplate) {
$this->htemplate= $tmplate;
}
Set Output file name
function sethtml ($filename) {
$this->filename= $filename;
}
Sets the name of the tag and the corresponding string to be replaced
function Editableblock ($name, $replace) {
$this->modistring[$name]= $replace;
}
Write HTML file
function writehtml () {
$FC =file ($this->htemplate);
$FP =fopen ($this->filename, "w");
$k =count ($FC);
$begin =false;
$first =false;
$tag = "";
for ($i =0; $i < $k; $i + +) {
if (Isbegin ($FC [$i])) {
Fputs ($fp, $FC [$i]);
$begin =true;
$first =true;
$tag =getname ($FC [$i]);
Continue
}
if (Isfinish ($FC [$i])) {
Fputs ($fp, $FC [$i]);
$begin =false;
$first =false;
$tag = "";
Continue
}
if ($begin ==true) {
if ($first ==true) {
$FC [$i]= $this->modistring[$tag]. " ";
$first =false;
}
else $FC [$i]= "";
}
Fputs ($fp, $FC [$i]);
}
Fclose ($FP);
}
--------class End
}
?>