Php article content pagination and generate corresponding htm static page code _ PHP Tutorial

Source: Internet
Author: User
The php article content is paginated and the corresponding htm static page code is generated. Copy the code as follows :? Php $ urltest. php? 11; $ contentsfjka; fjsa; # page # generate files in batches and add paging code; $ ptext # page #; ContentsPages ($ url, $ contents, $ p The code is as follows:


$ Url = 'Test. php? 1 = 1 ';
$ Contents = "fjka; fjsa; # page # generate files in batches and add paging code ";
$ Ptext = '# page #';
ContentsPages ($ url, $ contents, $ ptext)
/**
* Function name: ContentsPages
* Function: pagination of article content
* Parameter: $ url document content page URL type string, $ contents document content page content type string, $ ptext paging Identifier type string
* Author: seven nights
* QQ: 64438136 linus.php@gmail.com MSN: zhijian@live.com
*/
// Document array
$ Arr = explode ($ ptext, $ contents );
// Array length & total number of pages
$ Total = count ($ arr );
// Current page
$ Nowpage = $ _ GET ['Pages ']? $ _ GET ['Page']: 1;
// Previous Page
$ Prepage = $ nowpage = 1? 1: $ nowpage-1;
// Next page
$ Nextpage = $ nowpage> $ total-1? $ Total: $ nowpage + 1;
// Last Page
$ Lastpage = $ total;
$ Pp ='

';
$ Pp. = "page {$ nowpage}/total page {$ total ";
// Home page
$ Pp. ="

  • Homepage
  • ";
    // Link to the previous page
    $ Pp. ="
  • Previous Page
  • ";
    // Display the page List
    $ Color = '';
    For ($ I = 1; $ I <= $ total; $ I ++)
    {
    If ($ I = $ nowpage)
    {
    $ Color = "color: # ff0000 ;";
    }
    Else
    {
    $ Color = '';
    }
    $ Pp. ="
  • {$ I}
  • ";
    }
    // Link to the next page
    $ Pp. ="
  • Next page
  • ";
    // Last link
    $ Pp. ="
  • Last page
  • ";
    $ Pp. ='

    ';
    // Output Content
    Echo $ arr [$ nowpage-1];
    // If no page is displayed, the page list is not displayed.
    If ($ total <= 1) $ pp = '';
    // Output pagination list
    Echo $ pp;
    ?>


    The following is the related static generation page. Although the code is incorrect, the idea is correct.

    The code is as follows:


    $ TmpBody = "fjka; fjsa; {page}: generate multiple files and add paging code ";
    $ TmpUrl = 'www .jb51.net ';
    $ TmpUrlarray = explode ('.', $ tmpUrl );
    $ TmpArray = explode ('{page}', $ tmpBody );
    $ Total = count ($ tmpArray );
    $ Id = "2 ";
    If ($ total> 1)
    {
    $ TmpStr = '';
    For ($ I = 0; $ I <$ total; $ I ++) // traverses all pages
    {
    If ($ I = 0)
    {
    $ Str. = ''. ($ I + 1 ).'';
    }
    Else
    {
    $ Str. = ''. ($ I + 1 ).'';
    }
    }
    // Generate files in batches and add paging code
    $ Str ='

    '. $ Str .'

    ';
    For ($ j = 0; $ j <$ total; $ j ++)
    {
    If ($ j = 0)
    {
    $ Fname your id.'.htm ';
    }
    Else
    {
    $ Fname your id.'_'.w.j.'.htm ';
    }
    $ TempMu = str_replace ('{htmlContent}', $ tmpArray [$ j]. $ str, $ tempLate );
    MakeHtml ($ tempMu, $ filePath, $ fname); // The code for creating a file is not described in this function.
    }
    $ Mupage = 1;
    }
    $ TempLate = str_replace ('{htmlContent}', $ tmpBody, $ tempLate); // common articles are retrieved by {page} and saved to an array to generate a paging address, then the htm page is generated based on the content of The explode array.
    $ Total = 0;
    $ Str = '';
    $ I = 0;
    $ J = 0;
    /*
    The origin of the code is the id_page number, such as 100_1.htm,100_2.htm.
    */
    Function makeHtml ($ tempMu, $ filePath, $ fname ){
    $ Fp = fopen ($ filePath. $ filename, "w ");
    Fwrite ($ fp, $ tempMu );
    Fclose ($ fp );
    }
    ?>

    The http://www.bkjia.com/PHPjc/321989.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321989.htmlTechArticle code is as follows :? Php $ url = 'Test. php? 1 = 1'; $ contents = "fjka; fjsa; # page # generate files in batches and add paging code"; $ ptext = '# page #'; ContentsPages ($ url, $ contents, $ p...

    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.