Paging article content and generating corresponding htm static page code_PHP tutorial

WBOY
Release: 2016-07-21 15:37:21
Original
875 people have browsed it

Copy code The code is as follows:

$url='test.php?1=1 ';
$contents="fjka;fjsa;#page#Batch generate files into files and add paging code";
$ptext ='#page#';
ContentsPages($url,$contents, $ptext)
/**
* Function name: ContentsPages
* Function: Article content paging
* Parameters: $url article content page URL type string, $contents article content page content type string, $ptext paging identification type string
* Author: Qiye
* QQ:64438136 linus.php@gmail.com MSN:zhijian@live.com
*/
//Array of articles
$arr = explode($ptext,$contents);
//Array length & total number of pages
$total = count($arr);
//Current page
$nowpage = $_GET['pages']?$_GET['pages']:1;
//Previous page
$prepage = $nowpage==1?1:$nowpage-1;
//Next page
$nextpage = $nowpage>$total-1?$total:$nowpage+1;
// Last page
$lastpage = $total;
$pdiv = '
';
$pdiv .= "{$nowpage}/Total {$total} pages ";
//Homepage link
$pdiv .= "
  • Homepage
  • ";
    // Previous page link
    $pdiv .= "
  • Previous page
  • ";
    //Display paginated list
    $color = '';
    for($i = 1; $i<=$ total; $i++)
    {
    if($i == $nowpage)
    {
    $color= "color:#ff0000;";
    }
    else
    {
    $color = '';
    }
    $pdiv .= "
  • {$i}
  • ";
    }
    //Next page link
    $pdiv .= "
  • Next page
  • ";
    //Last page link
    $pdiv .= "
  • Last page
  • ";
    $pdiv .= '
    ';
    //Output content
    echo $arr[$nowpage-1];
    //Do not display the paginated list if it is not paginated
    if( $ total <=1) $pdiv = '';
    //Output paging list
    echo $pdiv;
    ?>

    The following is the relevant statically generated page, although The code is incorrect but the idea is fine.
    Copy code The code is as follows:

    $tmpBody = "fjka;fjsa;{page}batch Generate split 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++ ) //Traverse all pages
    {
    if( $i==0 )
    {
    $str .=''.($i+1).' ';
    }
    else
    {
    $str .=''.($i+1).'< ;/a> ';
    }
    }
    //Batch generate files and add paging code
    $str = '
    '.$str.'< /div>';
    for( $j=0;$j<$total;$j++ )
    {
    if( $j==0 )
    {
    $fname =$ id.'.htm';
    }
    else
    {
    $fname =$id.'_'.$j.'.htm';
    }
    $tempMu = str_replace('{htmlContent}',$tmpArray[$j].$str,$tempLate);
    makeHtml($tempMu,$filePath,$fname); //This function will not be explained, it is a file creation function Code
    }
    $mupage =1;
    }
    $tempLate = str_replace('{htmlContent}',$tmpBody,$tempLate); //Ordinary articles are taken out in {page} and saved to An array is regenerated into the paging address, and then the htm page is generated from the contents of the array divided by explode.
    $total=0;
    $str='';
    $i=0;
    $j =0;
    /*
    The principle of generating this code is that the id_page number is in the form of 100_1.htm, 100_2.htm. First,
    */
    function makeHtml($tempMu, $filePath,$fname){
    $fp = fopen($filePath.$filename, "w");
    fwrite($fp, $tempMu);
    fclose($fp);
    }
    ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321989.htmlTechArticleCopy the code as follows: ?php $url='test.php?1=1'; $contents=" fjka;fjsa;#page#Batch generate into files and add paging code"; $ptext ='#page#'; ContentsPages($url,$contents,$p...
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!