一个php分页函数

<?php
function NumeralPage($p,$page,$baseUri){
if($page>1 && $p<=$page){
$firstPage = $p == 0 ? “<span>首页</span>” : (‘<a href=”‘.$baseUri.'”>首页</a>’);
$lastPage = $p == 0 ? ” : (‘<a href=”‘.$baseUri. ‘&p=’ . ($p – 1) . ‘”>上页</a>’);
$previousPages=”;
for ($i=max(array(0,$p-4));$i<$p;$i++){
$previousPages.='<a href=”‘.$baseUri. ‘&p=’ . $i . ‘”>’.($i+1).'</a>’;
}
$currentPage='<span>’ . ($p + 1) . ‘</span>’;
$nextPages=”;
for ($i=$p+1,$end=min(array($page,$p+5));$i<$end;$i++){
$nextPages.='<a href=”‘.$baseUri. ‘&p=’ . $i . ‘”>’.($i+1).'</a>’;
}
$nextPage = $p == $page – 1 ? ” : (‘<a href=”‘.$baseUri. ‘&p=’ . ($p + 1) . ‘”>下页</a>’);
$endPage = $p == $page – 1 ? “<span>尾页</span>” : (‘<a href=”‘.$baseUri. ‘&p=’ . ($page – 1) . ‘”>尾页</a>’);
return ‘<div>’.$firstPage.$lastPage.$previousPages.$currentPage.$nextPages.$nextPage.$endPage.'</div>’;
}else{
return ”;
}
}
?>

发表评论