pagenum = ceil($count/$pagesize); $this->pagesize = $pagesize; $this->page =(isset($_GET['p'])&&$_GET['p']>0) ? intval($_GET['p']) : 1; } /** * 获得 url 后面GET传递的参数 */ public function getUrl(){ $url = 'index.php?'.http_build_query($_GET); $url = preg_replace('/[?,&]p=(\w)+/','',$url); $url .= (strpos($url,"?") === false) ? '?' : '&'; return $url; } /** * 获得分页HTML */ public function getPage(){ $url = $this->getUrl(); $start = $this->page-5; $start=$start>0 ? $start : 1; $end = $start+9; $end = $endpagenum ? $end : $this->pagenum; $pagestr = ''; if($this->page>5){ $pagestr = "首页 "; } if($this->page!=1){ $pagestr.= "上一页"; } for($i=$start;$ipage!=$this->pagenum){ $pagestr.="下一页"; } if($this->page+5pagenum){ $pagestr.="尾页 "; } return $pagestr; } } // 测试代码 $page = new page(100,10); $str=$page->getPage(); echo $str; ?>