The code is as follows:
<?php
$url = ' test.php?1=1 ';
$contents = "FJKA;FJSA; #page # batch generation into files and add pagination code";
$ptext = ' #page # ';
Contentspages ($url, $contents, $ptext)
/**
* Function Name: contentspages
* Function: article content pagination
* Parameters: $url article content page URL type string, $contents article content page content type string, $ptext paging identity type string
* Seven nights
* qq:64438136 [email protected] msn:[email protected]
*/
Article array
$arr = Explode ($ptext, $contents);
Array length & Total 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 = ' <br/><div style=\ ' height:30px;width:500px;border:1px; Blackground-color: #ff0000; \ ">";
$pdiv. = "{$nowpage} page/Total {$total} page";
Home link
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages=1\ "style=\" text-decoration:none;\ "> Home </a></li> ";
Links on page
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$prepage}\ "style=\" text-decoration: None;\ "> Prev </a></li>";
Display a list of pages
$color = ";
for ($i = 1; $i <= $total; $i + +)
{
if ($i = = $nowpage)
{
$color = "color: #ff0000;";
}
Else
{
$color = ";
}
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$i}\ "style=\" text-decoration:none;\ " ><span style=\ "{$color}\" >{$i}</span></a></li> ";
}
Next page link
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$nextpage}\ "style=\" text-decoration: None;\ "> Next </a></li>";
Last link
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$lastpage}\ "style=\" text-decoration: None;\ "> End </a></li>";
$pdiv. = ' </div> ';
Output content
echo $arr [$nowpage-1];
Do not display a paged list without paging
if ($total <=1) $pdiv = ';
Output Paging list
Echo $pdiv;
?>
Here is the related static generation page, although the code is not correct but the idea is no problem.
Copy CodeThe code is as follows:
<?
$tmpBody = "FJKA;FJSA; {page} batch build into file and add pagination 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 pagination
{
if ($i ==0)
{
$str. = ' <a href= '. $id. HTM class= "bodypage" target=_self> '. ($i + 1). ' </a> ';
}
Else
{
$str. = ' <a href= '. $id. ' _ '. $i. htm class= "Bodypage" target=_self> ". ($i + 1). ' </a> ';
}
}
Batch build into files and add pagination code
$str = ' <div class= ' mupage > ' $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 does not explain that the code that creates the file
}
$mupage = 1;
}
$tempLate = Str_replace (' {htmlcontent} ', $tmpBody, $tempLate); Normal article with {page} paged out save to an array regenerating component page address, and then generate an HTM page from the contents of an array based on explode
$total = 0;
$str = ";
$i = 0;
$j = 0;
/*
This code generation principle is id_ page number, such as 100_1.htm,100_2.htm form, first
*/
function makehtml ($tempMu, $filePath, $fname) {
$fp = fopen ($filePath. $filename, "w");
Fwrite ($fp, $tempMu);
Fclose ($FP);
}
?>
PHP article content paging and generating corresponding HTM static page code