PHP Generate HTML static page, phphtml static page _php Tutorial

Source: Internet
Author: User

PHP generates HTML static page, phphtml static page


Function:

Generates HTML static pages from PHP and stores them in a directory created with the name of the year and month.
Read all data batch generation, all generated after the popup prompt.
You can specify the number of batches to be generated, no more than 800 is recommended, or the execution speed will be problematic.

For the Jbxue.com website features developed, the code for my original, generation speed generally.

(For well-known reasons, the data field name involved in the database has been changed and the part of the parameter filter has been removed for code clarity)

Description: The original dynamic address is moban.php?id=1, the post-generated address is html/200808/sell_1.html. Page.php is a paging program, published in this blog.

Page usage, save this code as make.php, using the method for the browser to access the number of make.php?t= &pg= page, such as make.php?t=300&pg=2, that is, each time 300 data generated, starting from the 2nd page of the data list, That is, skip the previous 300 bars. If you access make.php directly without any parameters, the default is 200 per build, starting from the first page.

Example:

  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 2carsell");
  9. $totle =mysql_num_rows ($result);
  10. $pagelist = $_get[t];
  11. if ($_get[t]==') {
  12. $pagelist =' $ ';
  13. }else{
  14. $pagelist =$_get[t];
  15. }
  16. $pager = New Pager ($totle,$pagelist);
  17. $datastat ="Total ". $pager->countall. " Bar, generate each time . $pager->countlist. " Create a ". $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 2carsell the ORDER by ID DESC limit $limitFrom, $pagelist");
  22. ?>
  23. "FONT-SIZE:14PX;" > echo $aa?> page Generation: echo $datastat?>
  24. PHP generates static pages
  25. Www.jbxue.com
  26. Print" "; </span></li><li><span class= "keyword" >while (<span class= "VARs" > $datauser =mysql_ Fetch_array (<span class= "VARs" > $result)) {</span></span></span></li><li> < /li><li><span class= "VARs" > $iid =<span class= "VARs" > $datauser [ID]; </span></span></li><li><span class= "VARs" > $html = <span class= "func" >file_get_ Contents (<span class= "string" > "/moban.php?id=". <span class= "VARs" > $iid. <span class= "string" > "") ; </span></span></span></span></span></li><li><span class= "VARs" > $sql =<span class= "string" > "SELECT * from 2carsell where id= $iid"; </span></span></li><li><span class= "VARs" > $data =mysql_fetch_array (mysql_query ( <span class= "VARs" > $sql)); </span></span></li><li><span class= "VARs" > $path =<span class= "func" >date (< span class= "string" > "Ym", <span class= "VARs" > $data [putdate]); </span></span></span></span></li><li><span class= "VARs" > $testdir =< Span class= "string" > "html/". <span class= "VARs" > $path; </span></span></span></li><li><span class= "keyword" >if (<span class= "func" >file_exists (<span class= "VARs" > $testdir)): </span></span></span></li><li ><span class= "keyword" >else: </span></li><li><span class= "func" >mkdir (<span class= "VARs" > $testdir, 0777); </span></span></li><li><span class= "func" >echo <span class= "string" > "Directory" .< Span class= "VARs" > $testdir. <span class= "string" > "Created successfully! <br> "; </span></span></span></span></li><li><span class= "keyword" >endif; </span></li><li> </li><li><span class= "VARs" > $fileName = <span class= "string" > "html/$path/sell_$iid.html"; </span></span></li><li> </li><li><span class= "comment" >//use write mode to open $ FileName </span></li><li><span class= "keyword" >if (!<span class= "VARs" > $handle = < Span class= "func" >fopen (<span class= "VARs" > $filename, <span class= "string" > ' W ')) {</span></ Span></span></span></span></li><li>print <span class= "string" > "Cannot open File $ FileName "; </span></li><li><span class= "func" >exit; </span></li><li>} </li><li> </li><li><span class= "keyword" >if ( <span class= "func" >is_writable (<span class= "VARs" > $filename)) {</span></span></span ></li><li> </li><li><span class= "comment" >//writes $html to our open file. </span></li><li><span class= "keyword" >if (!fwrite(<span class= "VARs" > $handle, <span class= "VARs" > $html)) {</span></span></span></li><li>print <span class= "string" > "Cannot write to file $filename" ; </span></li><li><span class= "func" >exit; </span></li><li>} </li><li> </li><li>print <span class= "string" > " File $filename updated successfully! \n\r "; </span></li><li> </li><li>fclose (<span class= "VARs" > $handle); </span></li><li> </li><li>} <span class= "keyword" >else {</span></li ><li>print <span class= "string" > "File $filename not writable"; </span></li><li>} </li><li>?> </li><li><? }?> </li><li>


  27. "FONT-SIZE=12PX" > echo $datastat." "?>

  28. $AA =$aa +1;
  29. if ($aa >$bb) {
  30. Echo ' Congratulations, all pages generated! ';
  31. echo "";
  32. }else{
  33. echo "";
  34. }
  35. ?>

http://www.bkjia.com/PHPjc/1080760.html www.bkjia.com true http://www.bkjia.com/PHPjc/1080760.html techarticle PHP generates HTML static pages, phphtml static page functionality: Generates HTML static pages from PHP and stores them in a directory created with the name of the year and month. Read all data batch generation, all ...

  • Related Article

    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.