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...