<p> <code><?php<br />class Page{<br /> private $totalpage;<br /> private $stride;<br /> private $currentpage;<br /> //设置总页数<br /> function setTotalpage($objpage=0){<br /> $this->totalpage=$objpage;<br /> }<br /> //设置当前页<br /> function setCurrentpage($objpage=1){<br /> $this->currentpage=$objpage;<br /> }<br /> //设置跨度<br /> function setStride($objStride=1){<br /> $this->stride=$objStride;<br /> }<br /> //获得总页数<br /> function getTotalpage(){<br /> return $this->totalpage;<br /> }<br /> //获得跨读<br /> function getStride($objStride=1){<br /> return $this->stride;<br /> }<br /> //获取当前页<br /> function getCurrentpage($objpage=1){<br /> return $this->currentpage;<br /> }<br /> //打印分页<br /> function Pageprint(){<br /> for($Tmpa=0;$Tmpa<$this->totalpage;$Tmpa++){<br /> if($Tmpa+$this->stride<$this->currentpage){//加了跨度还小于当前页的不显示<br /> continue;<br /> }<br /> if($Tmpa+$this->stride==$this->currentpage){//刚好够跨度的页数<br /> $p=$this->currentpage-$this->stride-1;<br /> $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=1\"><strong><<</strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong><</strong></a> ";<br /> }<br /> if($Tmpa>$this->currentpage+$this->stride){//大于当前页+跨度的页面<br /> break;<br /> }<br /> $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$Tmpa\"><strong>$Tmpa</strong></a> ";<br /> if($Tmpa==$this->currentpage+$this->stride){//刚好够跨度的页数<br /> $p=$this->currentpage+$this->stride+1;<br /> $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong>></strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$this->totalpage\"><strong>>></strong></a>";<br /> }<br /> }<br /> echo $willprint;<br /> }<br />}<br />if(isset($_GET[page])){<br /> $page=$_GET[page];<br />}else{<br /> $page=1;<br />}<br />$CC=new Page();<br />$CC->setTotalpage(1000);<br />$CC->setCurrentpage($page);<br />$CC->setStride(5);<br />$CC->Pageprint();<br />?></code></p>