class page{
public $page;
public $pagenum;
public $pagesize;
public function __construct($count,$pagesize){
$this->pagenum=ceil($count/$pagesize);
$this->pagesize=$pagesize;
$this->page=(isset($_GET['p'])&&$_GET['p']>0)?intval($_GET['p']):1;//首次调用类么?是的话就让P值为1
}
public function getUrl(){
$url =basename($_SERVER['PHP_SELF']). '?'.http_build_query($_GET);
$url=preg_replace('/[?,&]p=(\w)+/','',$url);
$url.=(strpos($url,"?")===false)?'?':'&';
return $url;//这里返回的是没有P参数的URL
}
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="first page";
}
if($this->page!=1){
$pagestr="pre ";
}
for($i=$start;$i<=$end;$i++){
$pagestr.=" ".$i." ";
}
if($this->page!=$this->pagenum){
$pagestr.="next ";
}
if($this->page+5pagenum){
$pagestr.="last_page";
}
return $pagestr;
}
}
$page=new page(1000,7);
$str=$page->getPage();
echo $str;
?>