How to generate static HTML documents using PHP _ PHP Tutorial

Source: Internet
Author: User
Use PHP to generate static HTML documents. Code: Copy the code as follows :? Php introduces the database configuration FILE include (dirname (_ FILE _). includeconfig. php); ***** generate a single code for the articles in the database:

The code is as follows:


// Introduce the database configuration file
Include (dirname (_ FILE _). "\ include \ config. php ");

/**
*
* Generate a single HTML file from the database.
* @ Param Date $ Date
* @ Param Time $ Time
* @ Param String $ Content
* @ Param String $ Title
*/
Function GenerateHTML ($ Date, $ Time, $ Content, $ Title, $ Name ){

// Splits the date and time variables into arrays.
$ GetDateRow = explode ("-", $ Date );
$ GetTimeRow = explode (":", $ Time );

// Obtain the file name. For example: 20121028210632.html
$ FileName = $ GetDateRow [0]. $ GetDateRow [1]. $ GetDateRow [2]. $ GetTimeRow [0]. $ GetTimeRow [1]. $ GetTimeRow [2]. ". html ";

// Open and read the template content
$ FP = fopen ("tmp.html", "r ");
$ Str = fread ($ FP, filesize ("tmp.html "));

// Get the replaced Template content
$ Str = str_replace ("{Title}", $ Title, $ Str );
$ Str = str_replace ("{Content}", $ Content, $ Str );
$ Str = str_replace ("{Name}", $ Name, $ Str );
$ Str = str_replace ("{Date}", $ Date, $ Str );
$ Str = str_replace ("{Time}", $ Time, $ Str );

// Close the file to reduce the pressure on the server.
Fclose ($ FP );

// Write the content to an HTML file
$ Handle = fopen ($ FileName, "w ");
Fwrite ($ Handle, $ Str );
Fclose ($ Handle );

// Perform a minor test
// Echo "OK, done! ";

}

// Database operations
$ Querysql = "select * from article ";
$ Queryset = mysql_query ($ querysql );

// Generate HTML files cyclically.
While ($ row = mysql_fetch_array ($ queryset )){
GenerateHTML ($ row ['Date'], $ row ['Time'], $ row ['content'], $ row ['title'], $ row ['name']);
}

The pipeline code is as follows :? Php // introduce the database configuration FILE include (dirname (_ FILE __)). "\ include \ config. php ");/*** generate a single article in the database...

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.