在文章内分页的php函数

在文章内分页的php函数

function Cut_Page($str,$url=”,$cut=”){

$cut = ($cut==”)?$cut='[page]’:$cut;//默认的分页标签为[page]
$str_cut = explode(“$cut”,$str);//对要分页的内容按照$cut标记进行拆分
$total = intval(count($str_cut));//得到总页数
$url = ($url==”)?$url=$_SERVER[‘PHP_SELF’]:$url;//链接的页面
$page = isset($_GET[‘page’])?intval($_GET[‘page’]):1; //获得页码数,没有则默认为1
$nextpage = ($page==$total)?0:($page+1); //下一页
$uppage = ($page==1)?0:($page-1);//上一页

$pagenav = $str_cut[$page-1].'<br />’;

if($uppage==0)$pagenav .= “<span>上一页</span>”;
else$pagenav .= “<span><a href=$url?page=$uppage>上一页</a></span>”;
for($x=1;$x<=$total;$x++){
if($x==$page)$pagenav .= “<span>”;
else$pagenav .= “<span><a href=$url?page=$x>”;
$pagenav .= $x;
if($x==$page)$pagenav .= ‘</span>’;
else$pagenav .= ‘</a></span>’;
}
if($nextpage==0)$pagenav .= “<span>下一页</span>”;
else$pagenav .= “<span><a href=$url?page=$nextpage>下一页</a></span>”;

echo “<div class=’pb’><div class=’pagebox’>”.$pagenav.”</div></div>”;
}

转载自:疯中舞步 梦的河流

滚动至顶部