PHP generates static HTML documents to implement code _php techniques

Source: Internet
Author: User

The

uses PHP to generate a single HTML document from the article data in the database. First of all, conducive to the search engine included. Second, it is safer to avoid exposing fields in the database to the Address bar.
Give code:

<?php//introduces the database configuration file include (DirName (DirName (__file__)). "

\include\config.php ");
 /** * * Generates 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) {//to decompose the date and time variables into groups $GetDateRow = explode ("-", $Date); $GetTimeRow = Explode (":", $Time); Get the name of the file. 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 server pressure.

Fclose ($FP);
Writes content to an HTML file $Handle = fopen ($FileName, "w");
Fwrite ($Handle, $STR);

Fclose ($Handle);

Small test//echo "ok,done!"; }//Database Operations $querysql = "SELECT * FROM Article ";

$queryset = mysql_query ($querysql);
Loops to generate HTML files. while ($row = Mysql_fetch_array ($queryset)) {generatehtml ($row [' Date '], $row [' time '], $row [' content '], $row [' title '],
$row [' name ']);

 }

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.