PHP article content paging and generate the corresponding HTM static page code _php tips

Source: Internet
Author: User
Tags array length explode

Copy Code code as follows:

<?php
$url = ' test.php?1=1 ';
$contents = "Fjka;fjsa #page # Batch generation into file and plus paging 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
* Author: seven nights
* qq:64438136 linus.php@gmail.com msn:zhijian@live.com
*/
Article array
$arr = Explode ($ptext, $contents);
Array length & Total pages
$total = count ($arr);
Current page
$nowpage = $_get[' pages ']?$_get[' pages ']:1;
Up 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> ";
Link Up page
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$prepage}\ "style=\" text-decoration: None;\ "> Prev </a></li>";
Display a page-list
$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=\" ><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 page </a></li>";
Last link
$pdiv. = "<li style=\" display:inline;\ "><a href=\" {$url}&pages={$lastpage}\ "style=\" text-decoration: None;\ "> Last </a></li>";
$pdiv. = ' </div> ';
Output content
echo $arr [$nowpage-1];
No paging list is displayed without paging
if ($total <=1) $pdiv = ';
Output Paging list
Echo $pdiv;
?>

The following is a related static generated page, although the code is not correct but the idea is no problem.
Copy Code code as follows:

?
$tmpBody = "FJKA;FJSA; {page} batch generation divided into files and plus 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 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 generation into file and plus paging 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 a file creation code
}
$mupage = 1;
}
$tempLate = Str_replace (' {htmlcontent} ', $tmpBody, $tempLate); Regular articles are saved in {page} paging to an array Regeneration component page address, and then the HTM page is generated 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 in the form of the first
*/
function makehtml ($tempMu, $filePath, $fname) {
$fp = fopen ($filePath. $filename, "w");
Fwrite ($fp, $tempMu);
Fclose ($FP);
}
?>

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.