How PHP generates static HTML documents,

Source: Internet
Author: User

How PHP generates static HTML documents,


Use PHP to generate a single HTML document from the document data in the database. First, it is beneficial to search engines. Second, it is safer to avoid exposing fields in the database to the address bar.
Code:

<? Php // introduce the Database Configuration FILE include (dirname (_ FILE __)). "\ include \ config. php ");/***** generate a single HTML file for the articles in 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); // get 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 pressure on the server. Fclose ($ FP); // write the content to the HTML file $ Handle = fopen ($ FileName, "w"); fwrite ($ Handle, $ Str ); fclose ($ Handle); // quiz // 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']);}

OK, DONE!

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.