The so-called content pagination, is based on your own set of labels, the longer content according to the label you set to page, this article covers two places, one is the acquisition of the address, the Internet has many such paging tutorials, but the address is fixed, if the page has comments page and the article ID call over, it will be very troublesome, In this paper, the idea of paging principle (http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/2009/0416/807.html) in PHP100 video tutorial is adopted. There are not clear children's shoes can look at this tutorial, while using some content processing functions as well as the knowledge of the array, I wrote this article for the first time, the expression is not clear also please forgive me
First look at the effect of the picture:
For more of these paging effects, there are many of these styles in the Php100 forum, where you share the CSS style code in the picture:
Css:
- Div.digg {padding-right:3px; padding-left:3px; padding-bottom:3px; margin:3px; padding-top:3px; Text-align:center}
- Div.digg A {border-right: #aaaadd 1px solid; padding-right:5px; Border-top: #aaaadd 1px solid; padding-left:5px; padding-bottom:2px; margin:2px; Border-left: #aaaadd 1px solid; COLOR: #000099; padding-top:2px; Border-bottom: #aaaadd 1px solid; Text-decoration:none}
- Div.digg a:hover {border-right: #000099 1px solid; Border-top: #000099 1px solid; Border-left: #000099 1px solid; COLOR: #000; Border-bottom: #000099 1px solid}
- Div.digg a:active {border-right: #000099 1px solid; Border-top: #000099 1px solid; Border-left: #000099 1px solid; COLOR: #000; Border-bottom: #000099 1px solid}
- Div.digg span.current {border-right: #000099 1px solid; padding-right:5px; Border-top: #000099 1px solid; padding-left:5px; Font-weight:bold; padding-bottom:2px; margin:2px; Border-left: #000099 1px solid; COLOR: #fff; padding-top:2px; Border-bottom: #000099 1px solid; Background-color: #000099}
- Div.digg span.disabled {border-right: #eee 1px solid; padding-right:5px; Border-top: #eee 1px solid; padding-left:5px; padding-bottom:2px; margin:2px; Border-left: #eee 1px solid; COLOR: #ddd; padding-top:2px; Border-bottom: #eee 1px solid}
PHP Code:
- <?php
- $contents = "Fjka;fjsa #page # Batch production [newpage] #page # Composition written #page# and added #page# paging code"; The original content with the paging label
- $cons = "Fjka;fjsa;adsfasdfas code"; Original content without pagination label
- function Conpage ($contents) {
- $pagesss = "#page #"; Set Pagination label
- $a =strpos ($contents, $pagesss);
- if ($a) {
- $con =explode ($pagesss, $contents);
- $cons =count ($con);
- @ $p = ceil ($_get["P"]);
- if (! $p $p<0) $p = 1;
- $url =$_server["Request_uri"];
- $parse _url=parse_url ($url);
- $url _query= $parse _url["Query"];
- if ($url _query) {
- $url _query=ereg_replace ("(^&) p= $p", "", $url _query);
- $url =str_replace ($parse _url["Query"), $url _query, $url);
- if ($url _query) $url. = "&p"; else $url. = "P";
- }else {
- $url. = "P";
- }
- if ($cons <=1) return false;//do not show paging when only one page
- $pagenav = "<div class=\" digg\ ">";
- for ($i =1; $i <= $cons; $i + +) {
- if ($i = = $p) {
- $pagenav. = "<span class=" Current ">". $p. " </span> ";
- }else{
- $pagenav. = "<a href=" $url = $i "> $i </a>";
- }
- }
- $pagenav. = "</div>";
- return $con [$p-1]. $pagenav;
- }else{
- return $contents;
- }
- }
- echo Conpage ($contents); With a paging label
- echo Conpage ($cons); With no paging label
- ?>
This article for PHP100 Chinese Community original works, please reprint the source: http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/1201/6940.html