A class that generates a static HTML file from a template file

Source: Internet
Author: User
Tags class definition continue ereg

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
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.