Home >Backend Development >PHP Tutorial >PHP 长稿子分页 手动插入分页标签
PHP 长文章分页 手动插入分页标签
<?php $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'.$p.''; }else{ $pagenav.="<a href="%24url=%24i">$i</a>"; } } $pagenav.=""; return $con[$p-1].$pagenav; }else{ return $contents; } } echo conpage($contents); ?>