PHP动态分页函数,PHP开发分页必备啦。其实吧,这个是必用的,不说了,PHP动态分页函数还是不错,比较简单吧
贴代码:
复制代码 代码如下:
/**
* 分页函数
*
* @param int $count 条目总数
* @param int $perlogs 每页显示条数目
* @param int $page 当前页码
* @param string $url 页码的地址
*/
function pagination($count,$perlogs,$page,$url,$anchor=''){
$pnums = @ceil($count / $perlogs);
$re = '';
$urlHome = preg_replace("|[\?&/][^\./\?&=]*page[=https://www.jb51.net/\-]|","",$url);
for ($i = $page-5;$i <= $page+5 && $i <= $pnums; $i++){
if ($i > 0){
if ($i == $page){
$re .= " <span>$i</span> ";
} elseif($i == 1) {
$re .= " <a href=https://www.jb51.net/article/\"$urlHome$anchor\">$i</a> ";
} else {
$re .= " <a href=https://www.jb51.net/article/\"$url$i$anchor\">$i</a> ";
}
}
}
if ($page > 6) $re = "<a href=https://www.jb51.net/article/\"{$urlHome}$anchor\" title=https://www.jb51.net/article/\"首页\">«</a><em>...</em>$re";
if ($page + 5 < $pnums) $re .= "<em>...</em> <a href=https://www.jb51.net/article/\"$url$pnums$anchor\" title=https://www.jb51.net/article/\"尾页\">»</a>";
if ($pnums <= 1) $re = '';
return $re;
}
您可能感兴趣的文章: