PHP static page generation-PHP source code

Source: Internet
Author: User
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;
}

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.