Ec (2); & lt ;? Phpdate_default_timezone_set (& quot; AsiaShanghai & quot;); classTCreateHTML {var $ HTemplate; Template File var $ FileName; new file name var $ HTFilePath; Path of the generated file var $ ModiString; var $ ReText script ec (2); script
Date_default_timezone_set ("Asia/Shanghai ");
Class TCreateHTML {
Var $ HTemplate; // Template File
Var $ FileName; // new file name
Var $ HTFilePath; // path of the generated file
Var $ ModiString;
Var $ ReTextArray; // Replace the information array
Var $ strText = ""; // text content
Var $ CrType = "1"; // The default type of the generated file name is date + 4-digit random number.
Var $ errorStr; // error message!
// ******** Interface function
// Construct a template
Function TCreateHTML (){}
// Create a file
Function CreatrHtml ()
{
// Check whether the template path is valid
If (! $ This-> CheckPath ($ this-> HTemplate, "0 "))
{
Return false;
}
// Check whether the path of the new file is valid
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 content in the template
Fclose ($ fp );
// Replace the file
$ This-> ReplaceText ();
// Generate the file name
$ This-> CreateName ();
$ Handle = fopen ($ this-> FileName, "w"); // write mode to open the news path
Fwrite ($ handle, $ this-> strText); // write the replaced content into the generated HTML file.
Fclose ($ handle );
Return true;
}
Function CheckPath ($ pStr, $ type)
{
If ($ type = "0 ")
{
If (! File_exists ($ pStr ))
{
$ This-> errorStr = "the folder path is incorrect! ";
Return false;
}
} Else
{
$ ArrPath = explode ("/", $ pStr );
$ S_Path = "";
Foreach ($ arrPath as $ tag ){
If ($ s_Path = "")
{
$ S_Path. = $ tag;
} Else
{
$ S_Path. = "/". $ tag;
}