Home >Backend Development >PHP Tutorial >PHP long article paging implementation code
This article introduces an entry-level example of pagination for long articles for the reference of beginners.
Before, we have also introduced the related content of article pagination. The one given here is relatively simple and suitable for beginners to use as a reference. Friends who want to advance can refer to the following articles: php article paging implementation code php text article pagination code example php code to implement paging display of long articles Sample code: <?php /** * 长文章分页 手动插入分页标签 * site bbs.it-home.org */ $contents = $rs['content']; function conpage($contents) { $pagesss='#page#'; //设定分页标签 $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;//只有一页时不显示分页 $pagenav="<div class=\"lyztpage\">"; for($i=1;$i<=$cons;$i++){ if($i==$p){ $pagenav.='<span class="current">'.$p.'</span>'; }else{ $pagenav.="$i"; } } $pagenav.="</div>"; return $con[$p-1].$pagenav; }else{ return $contents; } } //调用 echo conpage($contents); ?> |