PHP generate HTML static page_php tutorial

Source: Internet
Author: User
Tags month name
PHP generates HTML static pages. Generate an HTML static page from PHP and store it to the directory created with the year and month name. Read all data for batch generation. a prompt is displayed after all data is generated. You can specify the number of batch builds and create

Generate an HTML static page from PHP and store it to the directory created with the year and month name.
Read all data for batch generation. a prompt is displayed after all data is generated.
You can specify the number of batches generated. we recommend that you do not exceed 800. Otherwise, the execution speed may be faulty.

Developed for the jbxue.com website function. the code is self-generated and the generation speed is average.

(For a well-known reason, the data field name involved in the database has been changed, and the parameter filtering is removed for the sake of code clarity)

Note: The original dynamic address is moban. php? Id = 1. the generated URL is html/200808/sell_1.html. Page. php is a paging program, which has been released in this blog.

Page usage: save this code as make. php. how can I access make. php in a browser? T = quantity & pg = Page; for example, make. php? T = 300 & pg = 2, that is, 300 pieces of data are generated each time, starting from page 1 of the data list, that is, the first 2nd pieces are skipped. If you directly access make. php without adding any parameters, 200 entries are generated each time by default, starting from the first page.

Example:

Php code
  1. If ($ _ GET [pg] = ''){
  2. $ Aa = 1;
  3. } Else {
  4. $ Aa = $ _ GET [pg];
  5. }
  6. Include ("admin/conn. php ");
  7. Require_once ("page. php ");
  8. $ Result = mysql_query ("select * from 2 cartid ");
  9. $ Totle = mysql_num_rows ($ result );
  10. $ Pagelist = $ _ GET [t];
  11. If ($ _ GET [t] = ''){
  12. $ Pagelist = '20140901 ';
  13. } Else {
  14. $ Pagelist = $ _ GET [t];
  15. }
  16. $ Pager = new Pager ($ totle, $ pagelist );
  17. $ Datastat = "total". $ Pager-> countall ."Entries, generated each time". $ Pager-> countlist ."Items to be generated". $ Pager-> page ."Times "; // data statistics
  18. $ Bb = $ pager-> page;
  19. $ Pagenav = $ pager-> backstr. $ pager-> thestr. $ pager-> nextstr;
  20. $ LimitFrom = $ pagelist * ($ pager-> PG-1 );
  21. $ Result = mysql_query ("select * from 2 carrentorder BY id DESC limit $ limitFrom, $ pagelist ");
  22. ?>
  23. The Page generation ..


  24. // Php generates a static page
  25. // Www.jbxue.com
  26. Print" "; </Li> <li> while ($ datauser = mysql_fetch_array ($ result )) {</li> <li> $ iid = $ datauser [id]; </li> <li> $ html = file_get_contents ("/moban. php? Id = ". $ iid. ""); </li> <li> $ SQL = "select * from 2 cartid where id = $ iid "; </li> <li> $ data = mysql_fetch_array (mysql_query ($ SQL); </li> <li> $ path = date ("Ym ", $ data [PutDate]); </li> <li> $ testdir = "html /". $ path; </li> <li> if (file_exists ($ testdir): </li> <li> else: </li> <li> mkdir ($ testdir, 0777); </li> <li> echo "directory ". $ testdir. "created successfully! <Br> "; </li> <li> endif; </li> <li> $ filename =" html/$ path/sell_policiid.html "; </li> <li> // enable $ filename in write mode </li> <li> if (! $ Handle = fopen ($ filename, 'w') {</li> <li> print "the file $ filename cannot be opened"; </li> <li> exit; </li> <li >}</li> <li> if (is_writable ($ filename )) {</li> <li> // write $ html to the open file. </Li> <li> if (! Fwrite ($ handle, $ html) {</li> <li> print "cannot be written to the file $ filename"; </li> <li> exit; </li> <li >}</li> <li> print "file $ filename updated successfully! \ N \ r "; </li> <li> fclose ($ handle ); </li> <li >}else {</li> <li> print "file $ filename cannot be written "; </li> <li >}</li> <li >?> </Li> <? }?> </Li> <li>




  27. $ Aa = $ aa + 1;
  28. If ($ aa> $ bb ){
  29. Echo 'Congratulations, all pages have been generated! ';
  30. Echo "script" alert ('all documents have been generated/updated! ') Script ";
  31. } Else {
  32. Echo"

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.