PHP generates static HTML document implementation code. _ PHP Tutorial

Source: Internet
Author: User
PHP generates static HTML document implementation code ,. PHP generates static HTML document implementation code, and uses PHP to generate a single HTML document from the document data in the database. First, it is beneficial to search engines. Second, avoid generating static HTML document implementation code from PHP in the database,

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']);}

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Using PHP to generate a single HTML document from the document data in the database. First, it is beneficial to search engines. Second, avoid...

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.