pages = ceil($nums/$size); if ($cur_page > $this->pages) { $cur_page = $this->pages; } $this->page = $cur_page; $this->url_tpl = $url_tpl; } /** * * 获取指定页面的url * @param int $page * @return string */ private function pageUrl($page) { $url = str_replace('{page}', $page, $this->url_tpl); $url = str_replace('%7Bpage%7D', $page, $url);// 支持url被转义后的 return $url; } public function html() { $html = ''; # 显示上一页 if ($this->page > 1) { $prev_page = $this->page - 1; $html .= << 上一页 PAGE; } # 显示第1、2页 for ($i=1; $i<=$this->first_num; $i++) { if ($i >= $this->page-$this->nearby_num) { continue; } $html .= << {$i} PAGE; } if ($this->page > ($this->first_num+$this->nearby_num+1)) { $html .= '...'; } for ($i=$this->page-$this->nearby_num; $i <= $this->page+$this->nearby_num; $i++ ) { if ($i < 1) { continue; } if ($i > $this->pages) { continue; } if ($i == $this->page) { $html .= "{$i}"; } else { $html .= << {$i} PAGE; } } if ($this->page < $this->pages-$this->end_num-$this->nearby_num) { $html .= '...'; } # 显示倒数第1、2页 for ($i=$this->pages-$this->end_num+1; $i<=$this->pages; $i++) { if ($i <= $this->page+$this->nearby_num) { continue; } $html .= << {$i} PAGE; } # 显示下一页 if ($this->page < $this->pages) { $next_page = $this->page + 1; $html .= << 下一页 PAGE; } return $html; } }