| <?php class prge { private $couRow = 0; //当前总记录数 private $pageRow = 0; //每页显示数 private $couPage = 0; //当前总页数 private $nowPage = 0; //当前第几页 private $startRow = 0; //开始记录行号 private $nu_couPage = 0; //当前共有多少页 private $nu_nowPage = 0; //当前第几页 private $nu_pageRow = 0; //共显示几个页码 private $nu_startPage = 0; //开始显示页码 private $nu_loop = 0; //循环次数 /** * 构造函数 * * @param int $couRow 当前总记录数 * @param int $pageRow 每页显示数 * @param int $startRow 开始记录行号 */ public function __construct($couRow, $pageRow, $startRow) { $this->couRow = $couRow; $this->pageRow = $pageRow; $this->startRow = $startRow; $this->couPage = $this->nu_couPage = ceil($this->couRow/$this->pageRow); $this->nowpage = $this->nu_nowPage = $this->startRow/$this->pageRow; } /** * 第一页 * * @return int 开始记录号 0 */ public function firstPage() { return 0; } /** * 上一页 * * @return int 开始记录号 */ public function backPage() { return empty($this->startRow) ? 0 : $this->startRow-$this->pageRow; } /** * 下一页 * * @return int 开始记录号 */ public function nextPage() { return $this->startRow + $this->pageRow >= $this->couRow ? $this->startRow : $this->startRow + $this->pageRow; } /** * 最后一页 * * @return int 开始记录号 */ public function lastPage() { $temp_row = $this->pageRow * floor($this->couRow / $this->pageRow); return $temp_row == $this->couRow ? $temp_row-$pageRow : $temp_row; } /** * 数字分页(可显示固定分页个数) * * @param int $nu_pageRow 固定分页个数 */ public function nuPage($nu_pageRow) { $this->nu_pageRow = $nu_pageRow; //第一次判断,是否需要隐藏页码 if($this->nu_pageRow > $this->nu_couPage) { $this->nu_startPage = 0; $this->nu_loop = $this->nu_couPage; }else { //需要隐藏页码,有三种状态 $this->nu_pageOffset = ceil($this->nu_pageRow/2);//页码偏移量 3 //第一种状态 当前页-偏移量 < 0 如:2-3=-1 if($this->nu_nowPage - $this->nu_pageOffset < 0) { $this->nu_startPage = 0; $this->nu_loop = $this->nu_pageRow; }elseif ($this->nu_nowPage + $this->nu_pageOffset > $this->nu_couPage) {//第二种状态 当前页+偏移量 > 总页数 9 如:7+3=10 $this->nu_startPage = $this->nu_couPage - $this->nu_pageRow; $this->nu_loop = $this->nu_startPage + $this->nu_pageRow; }else {//第三种状态 中间循环 3-2 4-2 5-2 floor($nu_pageRow/2); $this->nu_startPage = $this->nu_nowPage - floor($this->nu_pageRow/2); $this->nu_loop = $this->nu_startPage + $this->nu_pageRow; } } //判断是否开启数字,显示长度 if($this->nu_pageRow == '0') { $this->nu_startPage = 0; $this->nu_loop = $this->nu_couPage; } for($i = $this->nu_startPage; $i < $this->nu_loop; $i++) { if($i * $this->pageRow == $this->startRow) { echo $i+1; }else { echo '<a href="?startRow=' . $i * $this->pageRow . '">' . ($i+1) . '</a>'; } } } /** * select 下拉分页 * */ public function selectNu() { $a = '<select onchange="window.location.href=this.value">'; for($i = 0; $i < $this->couPage; $i++) { if($i*$this->pageRow == $this->startRow) { $a.='<option value="?startRow=' . $i*$this->pageRow . '" selected>' . ($i+1) . '</option>'; }else { $a.= '<option value="?startRow=' . $i*$this->pageRow . '">' . ($i+1) . '</option>'; } } $a.= '</select>'; return $a; } /** * 分页样式 * * @return string [ 第一页 ][ 上一页 ][ 下一页 ][ 最后一页 ] */ public function getPage_1() { $return_val = ''; $return_val .= '<a href="?startRow='.$this->firstPage().'">[ 第一页 ]</a>'; $return_val .= '<a href="?startRow='.$this->backPage().'">[ 上一页 ]</a>'; $return_val .= '<a href="?startRow='.$this->nextPage().'">[ 下一页 ]</a>'; $return_val .= '<a href="?startRow='.$this->lastPage().'">[ 最后一页 ]</a>'; return $return_val; } /** * 释放内存 */ public function __destruct() { unset($couRow); unset($pageRow); unset($couPage); unset($nowPage); unset($startRow); unset($nu_couPage); unset($nu_nowPage); unset($nu_pageRow); unset($nu_startPage); unset($nu_loop); } } //文章内容分页一 function showPage($pagurl,$content){ //$pagurl:分页当前连接地址 //$content:需要分页的文章 $content = $content; $G_cfg = '{showpage}';// 分页符 $arr_content = explode($G_cfg, $content); // 按分页符把文章内容切成数组 $page = @(int)$_GET['page']; // GET传递页码page参数 $pamount= sizeof($arr_content); // 所切数组的大小 if($page <= 0) $page = 1; // 当$page不存在时,为首页 if($page > $pamount && $pamount > 0) $page = $pamount; // 当$page大于数组大小值时,为尾页 $content = $arr_content[$page-1]; $strpage = ''; if($pamount > 1) { for($i=0;$i<$pamount;$i++) { if($i+1 == $page) { $strpage .= ' <span style="color:red">' . ($i+1) . '</span> '; } else { $strpage .= ' <a href="'.$pagurl.'?id=' .$id. '&page=' .($i+1). '" title="' . $article_title . ' 第' .($i+1).'页" target="_self">'.($i+1).'</a> '; } } $strpage = substr($strpage, 0, strlen($strpage)-3); } return $content."<br />".$strpage; } //文章内容分页二 function showPage2($pagurl,$id,$content){ //$pagurl:分页当前连接地址 //$content:需要分页的文章 $content = $content; $G_cfg = '{showpage}';// 分页符 $arr_content = explode($G_cfg, $content); // 按分页符把文章内容切成数组 $page = @(int)$_GET['page']; // GET传递页码page参数 $pamount= sizeof($arr_content); // 所切数组的大小 if($page <= 0) $page = 1; // 当$page不存在时,为首页 if($page > $pamount && $pamount > 0) $page = $pamount; // 当$page大于数组大小值时,为尾页 $content = $arr_content[$page-1]; $strpage = ''; if($pamount > 1) { for($i=0;$i<$pamount;$i++) { if($i+1 == $page) { $strpage .= ' <span style="color:red">' . ($i+1) . '</span> '; } else { $strpage .= ' <a href="'.$pagurl.'?about_id=' .$id. '&page=' .($i+1). '" title="' . $article_title . ' 第' .($i+1).'页" target="_self">'.($i+1).'</a> '; } } $strpage = substr($strpage, 0, strlen($strpage)-3); } return $content."<br />".$strpage; } //文章内容分页三 function showPage3($pagurl,$id,$content){ //$pagurl:分页当前连接地址 //$content:需要分页的文章 $content = $content; $G_cfg = '{showpage}';// 分页符 $arr_content = explode($G_cfg, $content); // 按分页符把文章内容切成数组 $page = @(int)$_GET['page']; // GET传递页码page参数 $pamount= sizeof($arr_content); // 所切数组的大小 if($page <= 0) $page = 1; // 当$page不存在时,为首页 if($page > $pamount && $pamount > 0) $page = $pamount; // 当$page大于数组大小值时,为尾页 $content = $arr_content[$page-1]; $strpage = ''; if($pamount > 1) { for($i=0;$i<$pamount;$i++) { if($i+1 == $page) { $strpage .= ' <span style="color:red">' . ($i+1) . '</span> '; } else { $strpage .= ' <a href="'.$pagurl.'?class_id=' .$id. '&page=' .($i+1). '" title="' . $article_title . ' 第' .($i+1).'页" target="_self">'.($i+1).'</a> '; } } $strpage = substr($strpage, 0, strlen($strpage)-3); } return $content."<br />".$strpage; } |

