PHP generates HTML static pages

Source: Internet
Author: User
Tags month name

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. <? Php
  2. If ($ _ GET [pg] = ''){
  3. $ Aa = 1;
  4. } Else {
  5. $ Aa = $ _ GET [pg];
  6. }
  7. Include ("admin/conn. php ");
  8. Require_once ("page. php ");
  9. $ Result = mysql_query ("select * from 2 cartid ");
  10. $ Totle = mysql_num_rows ($ result );
  11. $ Pagelist = $ _ GET [t];
  12. If ($ _ GET [t] = ''){
  13. $ Pagelist = '20140901 ';
  14. } Else {
  15. $ Pagelist = $ _ GET [t];
  16. }
  17. $ Pager = new Pager ($ totle, $ pagelist );
  18. $ Datastat = "Total <B> ". $ pager-> countall. "</B>, generated each time <B> ". $ pager-> countlist. "</B>, which must be generated <B> ". $ pager-> page. "</B> times"; // data statistics
  19. $ Bb = $ pager-> page;
  20. $ Pagenav = $ pager-> backstr. $ pager-> thestr. $ pager-> nextstr;
  21. $ LimitFrom = $ pagelist * ($ pager-> pg-1 );
  22. $ Result = mysql_query ("select * from 2 carrentorder BY id DESC limit $ limitFrom, $ pagelist ");
  23. ?>
  24. <Center> <div style = "font-size: 14px;"> <B> NO. <font color = red> <? Echo $ aa?> </Font> page generation... <? Echo $ datastat?> </B> </div> <br>
  25. <?
  26. // Php generates a static page
  27. // Www.jbxue.com
  28. Print "<center> <textarea name = textarea class = textarea style = 'width: 520px; height: 455px '> ";
  29. While ($ datauser = mysql_fetch_array ($ result )){
  30. $ Iid = $ datauser [id];
  31. $ Html = file_get_contents ("/moban. php? Id = ". $ iid ."");
  32. $ SQL = "select * from 2 cartid where id = $ iid ";
  33. $ Data = mysql_fetch_array (mysql_query ($ SQL ));
  34. $ Path = date ("Ym", $ data [PutDate]);
  35. $ Testdir = "html/". $ path;
  36. If (file_exists ($ testdir )):
  37. Else:
  38. Mkdir ($ testdir, 0777 );
  39. Echo "directory". $ testdir. "created successfully! <Br> ";
  40. Endif;
  41. $ Filename = "html/$ path/sell_$iid.html ";
  42. // Enable $ filename in write mode
  43. If (! $ Handle = fopen ($ filename, 'w ')){
  44. Print "the file $ filename cannot be opened ";
  45. Exit;
  46. }
  47. If (is_writable ($ filename )){
  48. // Write $ html into the open file.
  49. If (! Fwrite ($ handle, $ html )){
  50. Print "cannot be written to file $ filename ";
  51. Exit;
  52. }
  53. Print "File $ filename updated successfully! \ N \ r ";
  54. Fclose ($ handle );
  55. } Else {
  56. Print "File $ filename cannot be written ";
  57. }
  58. ?>
  59. <? }?>
  60. </Textarea>
  61. <Br>
  62. <Div style = "font-size = 12px"> <? Echo $ datastat. ""?> </Div> <br>
  63. <?
  64. $ Aa = $ aa + 1;
  65. If ($ aa> $ bb ){
  66. Echo '<font color = blue> congratulations, all pages have been generated! </Font> ';
  67. Echo "<script> alert ('All documents have been generated/updated! ') </Script> ";
  68. } Else {
  69. Echo "<Script> window. location = 'make. php? T = $ pagelist & pg = $ aa '; </script> ";
  70. }
  71. ?>

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.