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!