最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

兩款萬(wàn)能的php分頁(yè)類(lèi)

 更新時(shí)間:2015年11月12日 11:31:52   投稿:lijiao  
這篇文章主要介紹了萬(wàn)能的php分頁(yè)類(lèi),特別好用,需要使用php分頁(yè)類(lèi)的朋友不要錯(cuò)過(guò)。

本文為大家分享個(gè)超級(jí)好用、萬(wàn)能的php分頁(yè)類(lèi),具體的實(shí)現(xiàn)代碼如下

第一款php分頁(yè)類(lèi)

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 * 分頁(yè)類(lèi)
 * 使用方式:
 * $page = new Page();
 * $page->init(1000, 20);
 * $page->setNotActiveTemplate('<span>&nbsp;{a}&nbsp;</span>');
 * $page->setActiveTemplate('{a}');
 * echo $page->show();
 * 
 * 
 * @author 風(fēng)居住的地方
 */
class Page {
  /**
   * 總條數(shù)
   */
  private $total;
  /**
   * 每頁(yè)大小
   */
  private $pageSize;
  /**
   * 總頁(yè)數(shù)
   */
  private $pageNum;
  /**
   * 當(dāng)前頁(yè)
   */
  private $page;
  /**
   * 地址
   */
  private $uri;
  /**
   * 分頁(yè)變量
   */
  private $pageParam;
  /**
   * LIMIT XX,XX
   */
  private $limit;
  /**
   * 數(shù)字分頁(yè)顯示
   */
  private $listnum = 8;
  /**
   * 分頁(yè)顯示模板
   * 可用變量參數(shù)
   * {total}   總數(shù)據(jù)條數(shù)
   * {pagesize}  每頁(yè)顯示條數(shù)
   * {start}   本頁(yè)開(kāi)始條數(shù)
   * {end}    本頁(yè)結(jié)束條數(shù)
   * {pagenum}  共有多少頁(yè)
   * {frist}   首頁(yè)
   * {pre}    上一頁(yè)
   * {next}    下一頁(yè)
   * {last}    尾頁(yè)
   * {list}    數(shù)字分頁(yè)
   * {goto}    跳轉(zhuǎn)按鈕
   */
  private $template = '<div><span>共有{total}條數(shù)據(jù)</span><span>每頁(yè)顯示{pagesize}條數(shù)據(jù)</span>,<span>本頁(yè){start}-{end}條數(shù)據(jù)</span><span>共有{pagenum}頁(yè)</span><ul>{frist}{pre}{list}{next}{last}{goto}</ul></div>';
  /**
   * 當(dāng)前選中的分頁(yè)鏈接模板
   */
  private $activeTemplate = '<li class="active"><a href="javascript:;">{text}</a></li>';
  /**
   * 未選中的分頁(yè)鏈接模板
   */
  private $notActiveTemplate = '<li><a href="{url}">{text}</a></li>';
  /**
   * 顯示文本設(shè)置
   */
  private $config = array('frist' => '首頁(yè)', 'pre' => '上一頁(yè)', 'next' => '下一頁(yè)', 'last' => '尾頁(yè)');
  /**
   * 初始化
   * @param type $total    總條數(shù)
   * @param type $pageSize  每頁(yè)大小
   * @param type $param    url附加參數(shù)
   * @param type $pageParam  分頁(yè)變量
   */
  public function init($total, $pageSize, $param = '', $pageParam = 'page') {
    $this->total = intval($total);
    $this->pageSize = intval($pageSize);
    $this->pageParam = $pageParam;
    $this->uri = $this->geturi($param);
    $this->pageNum = ceil($this->total / $this->pageSize);
    $this->page = $this->setPage();
    $this->limit = $this->setlimit();
  }
   
  /**
   * 設(shè)置分頁(yè)模板
   * @param type $template  模板配置
   */
  public function setTemplate($template) {
    $this->template = $template;
  }
   
  /**
   * 設(shè)置選中分頁(yè)模板
   * @param type $activeTemplate   模板配置
   */
  public function setActiveTemplate($activeTemplate) {
    $this->activeTemplate = $activeTemplate;
  }
 
  /**
   * 設(shè)置未選中分頁(yè)模板
   * @param type $notActiveTemplate  模板配置
   */
  public function setNotActiveTemplate($notActiveTemplate) {
    $this->notActiveTemplate = $notActiveTemplate;
  }
 
  /**
   * 返回分頁(yè)
   * @return type
   */
  public function show() {
    return str_ireplace(array(
      '{total}',
      '{pagesize}',
      '{start}',
      '{end}',
      '{pagenum}',
      '{frist}',
      '{pre}',
      '{next}',
      '{last}',
      '{list}',
      '{goto}',
    ), array(
      $this->total,
      $this->setPageSize(),
      $this->star(),
      $this->end(),
      $this->pageNum,
      $this->frist(),
      $this->prev(),
      $this->next(),
      $this->last(),
      $this->pagelist(),
      $this->gopage(),
    ), $this->template);
  }
   
  /**
   * 獲取limit起始數(shù)
   * @return type
   */
  public function getOffset() {
    return ($this->page - 1) * $this->pageSize;
  }
   
  /**
   * 設(shè)置LIMIT
   * @return type
   */
  private function setlimit() {
    return "limit " . ($this->page - 1) * $this->pageSize . ",{$this->pageSize}";
  }
 
  /**
   * 獲取limit
   * @param type $args
   * @return type
   */
  public function __get($args) {
    if ($args == "limit") {
      return $this->limit;
    } else {
      return null;
    }
  }
 
  /**
   * 初始化當(dāng)前頁(yè)
   * @return int
   */
  private function setPage() {
    if (!empty($_GET[$this->pageParam])) {
      if ($_GET[$this->pageParam] > 0) {
        if ($_GET[$this->pageParam] > $this->pageNum)
          return $this->pageNum;
        else
          return $_GET[$this->pageParam];
      }
    }
    return 1;
  }
 
  /**
   * 初始化url
   * @param type $param
   * @return string
   */
  private function geturi($param) {
    $url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], "?") ? "" : "?") . $param;
    $parse = parse_url($url);
    if (isset($parse["query"])) {
      parse_str($parse["query"], $params);
      unset($params["page"]);
      $url = $parse["path"] . "?" . http_build_query($params);
      return $url;
    } else {
      return $url;
    }
  }
 
  /**
   * 本頁(yè)開(kāi)始條數(shù)
   * @return int
   */
  private function star() {
    if ($this->total == 0) {
      return 0;
    } else {
      return ($this->page - 1) * $this->pageSize + 1;
    }
  }
 
  /**
   * 本頁(yè)結(jié)束條數(shù)
   * @return type
   */
  private function end() {
    return min($this->page * $this->pageSize, $this->total);
  }
 
  /**
   * 設(shè)置當(dāng)前頁(yè)大小
   * @return type
   */
  private function setPageSize() {
    return $this->end() - $this->star() + 1;
  }
   
  /**
   * 首頁(yè)
   * @return type
   */
  private function frist() {
    $html = '';
    if ($this->page == 1) {
      $html .= $this->replace("{$this->uri}&page=1", $this->config['frist'], true);
    } else {
      $html .= $this->replace("{$this->uri}&page=1", $this->config['frist'], false);
    }
    return $html;
  }
 
  /**
   * 上一頁(yè)
   * @return type
   */
  private function prev() {
    $html = '';
    if ($this->page > 1) {
      $html .= $this->replace($this->uri.'&page='.($this->page - 1), $this->config['pre'], false);
    } else {
      $html .= $this->replace($this->uri.'&page='.($this->page - 1), $this->config['pre'], true);
    }
    return $html;
  }
 
  /**
   * 分頁(yè)數(shù)字列表
   * @return type
   */
  private function pagelist() {
    $linkpage = "";
    $lastlist = floor($this->listnum / 2);
    for ($i = $lastlist; $i >= 1; $i--) {
      $page = $this->page - $i;
      if ($page >= 1) {
        $linkpage .= $this->replace("{$this->uri}&page={$page}", $page, false);
      } else {
        continue;
      }
    }
    $linkpage .= $this->replace("{$this->uri}&page={$this->page}", $this->page, true);
    for ($i = 1; $i <= $lastlist; $i++) {
      $page = $this->page + $i;
      if ($page <= $this->pageNum) {
        $linkpage .= $this->replace("{$this->uri}&page={$page}", $page, false);
      } else {
        break;
      }
    }
    return $linkpage;
  }
 
  /**
   * 下一頁(yè)
   * @return type
   */
  private function next() {
    $html = '';
    if ($this->page < $this->pageNum) {
      $html .= $this->replace($this->uri.'&page='.($this->page + 1), $this->config['next'], false);
    } else {
      $html .= $this->replace($this->uri.'&page='.($this->page + 1), $this->config['next'], true);
    }
    return $html;
  }
 
  /**
   * 最后一頁(yè)
   * @return type
   */
  private function last() {
    $html = '';
    if ($this->page == $this->pageNum) {
      $html .= $this->replace($this->uri.'&page='.($this->pageNum), $this->config['last'], true);
    } else {
      $html .= $this->replace($this->uri.'&page='.($this->pageNum), $this->config['last'], false);
    }
    return $html;
  }
 
  /**
   * 跳轉(zhuǎn)按鈕
   * @return string
   */
  private function gopage() {
    $html = '';
    $html.='&nbsp;<input type="text" value="' . $this->page . '" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.value;location=\'' . $this->uri . '&page=\'+page+\'\'}" style="width:25px;"/><input type="button" onclick="javascript:var page=(this.previousSibling.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.previousSibling.value;location=\'' . $this->uri . '&page=\'+page+\'\'" value="GO"/>';
    return $html;
  }
 
  /**
   * 模板替換
   * @param type $replace   替換內(nèi)容
   * @param type $result   條件
   * @return type
   */
  private function replace($url, $text, $result = true) {
    $template = ($result ? $this->activeTemplate : $this->notActiveTemplate);
     
     $html = str_replace('{url}', $url, $template);
     $html = str_replace('{text}', $text, $html);
    return $html;
  }
}

第二款php分頁(yè)類(lèi)

<?php
/*
 *本程序文件對(duì)分頁(yè)程序進(jìn)行了封裝
 *
*/

class Page_Link
{
  var $page_max = 10; //一組頁(yè)碼的最大數(shù)

  var $page_num = 10; //總頁(yè)數(shù)
  var $length = 20; //一頁(yè)的數(shù)據(jù)條數(shù)

  var $isNextPage = true;
  var $isFirstPage = false;

  function Calculation_Page_Num( $total )
  {
    $this->page_num = ceil( $total / $this->length );
    return $this->page_num;
  }

  function Calculation_Min_Max( $act_page = 1 )
  {
    // 定義左右偏移量
    $py_left = 0;
    $py_right = 0;
    // 定義左右邊界
    $bj_left = 0;
    $bj_right = 0;
    // 定義滾動(dòng)區(qū)間邊界
    $gd_left = 0;
    $gd_right = 0;
    // 判斷是否需要分組
    if ( ( $this->page_num - $this->page_max ) <= 0 )
    {
      // 不需要分組
      $bj_left = 1;
      $bj_right = $this->page_num;
    }
    else
    {
      // 要進(jìn)行分組
      // 判斷容量的奇偶
      $tmp = $this->page_max % 2;
      if ( $tmp === 1 )
      {
        // 奇數(shù)
        $py_left = $py_right = ( $this->page_max - 1 ) / 2;
      }
      else
      {
        // 偶數(shù)
        $py_left = $this->page_max / 2 - 1;
        $py_right = $this->page_max / 2;
      }
      // 計(jì)算滾動(dòng)區(qū)間
      $gd_left = 1 + $py_left;
      $gd_right = $this->page_num - $py_right;
      // 判斷當(dāng)前頁(yè)是否落入了滾動(dòng)區(qū)間
      if ( $act_page >= $gd_left && $act_page <= $gd_right )
      {
        // 區(qū)間內(nèi)
        $bj_left = $act_page - $py_left;
        $bj_right = $act_page + $py_right;
      }
      else
      {
        // 區(qū)間外
        if ( ( $act_page - $py_left ) <= 1 )
        {
          // 左側(cè)固定區(qū)間
          $bj_left = 1;
          $bj_right = $this->page_max;
        }
        else
        {
          $bj_left = $this->page_num - $this->page_max + 1;
          $bj_right = $this->page_num;
        }
      }
    }

    $res = array();
    $res['min'] = $bj_left;
    $res['max'] = $bj_right;

    return $res;
    
  }
  // 主方法
  function make_page( $total, $act_page, $url, $param )
  {
    $page_num = $this->Calculation_Page_Num( $total );
    $arr_min_max = $this->Calculation_Min_Max( $act_page );
    
    if (!eregi("([?|&]$param=)", $url)) {
      $url = strpos($url,"?")===false?$url."?":$url."&";
      $url = $url."$param=0";
    }

    if ( $act_page > $page_num )
    {
      $act_page = $page_num;
    }
    // 用正則把url改成正規(guī)的
    $url = eregi_replace( $param . '=[0-9]+', $param . '=0', $url );

    $res = array();
    $d = 0;
    for( $i = $arr_min_max['min'];$i <= $arr_min_max['max'];$i++ )
    {
      if ( $i == $act_page )
      {
        $res[$d]['url'] = '';
        $res[$d]['name'] = $i;
        $res[$d]['no'] = $i;
      }
      else
      {
        $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
        $res[$d]['name'] = $i;
        $res[$d]['no'] = $i;
      }
      $d++;
    }

    if ( $this->isNextPage )
    {
      $res = $this->make_before_next_link( $res, $act_page, $url, $param );
    }
    if ( $this->isFirstPage )
    {
      $res = $this->make_first_end_link( $res, $act_page, $url, $param );
    }
    return $res;
  }
  //// 帶總頁(yè)數(shù)
  function make_page_with_total( $total, $act_page, $url, $param )
  {
    $page_num = $this->Calculation_Page_Num( $total );
    $arr_min_max = $this->Calculation_Min_Max( $act_page );
    
    if (!eregi("([?|&]$param=)", $url)) {
      $url = strpos($url,"?")===false?$url."?":$url."&";
      $url = $url."$param=0";
    }

    if ( $act_page > $page_num )
    {
      $act_page = $page_num;
    }
    // 用正則把url改成正規(guī)的
    $url = eregi_replace( $param . '=[0-9]+', $param . '=0', $url );

    $res = array();
    $d = 0;
    for( $i = $arr_min_max['min'];$i <= $arr_min_max['max'];$i++ )
    {
      if ( $i == $act_page )
      {
        $res[$d]['url'] = '';
        $res[$d]['name'] = $i;
        $res[$d]['no'] = $i;
      }
      else
      {
        $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
        $res[$d]['name'] = $i;
        $res[$d]['no'] = $i;
      }
      $d++;
    }

    if ( $this->isNextPage )
    {
      $res = $this->make_before_next_link( $res, $act_page, $url, $param );
    }
    if ( $this->isFirstPage )
    {
      $res = $this->make_first_end_link( $res, $act_page, $url, $param );
    }
    
    $total_num= ceil($total/$this->length);
    $result['total']=$total_num;
    $result['DATA']=$res;
    return $result;
  }
  
  // 附加上一頁(yè)和下一頁(yè)
  function make_before_next_link( $arr, $act, $url, $param )
  {
    $tmp = array();

    $before = $act - 1;
    $next = $act + 1;

    if ( $before < 1 )
    {
      $before = 1;
      $tmp[0]['url'] = '';
      $tmp[0]['name'] = "上一頁(yè)";
      $tmp[0]['no'] = $before;
    }
    else
    {
      $tmp[0]['url'] = str_replace( $param . '=0', $param . '=' . $before, $url );
      $tmp[0]['name'] = "上一頁(yè)";
      $tmp[0]['no'] = $before;
    }

    $counts = sizeof( $arr );
    $tmp_count = sizeof( $tmp );
    for( $i = 0;$i < $counts;$i++ )
    {
      $tmp[$tmp_count]['url'] = $arr[$i]['url'];
      $tmp[$tmp_count]['name'] = $arr[$i]['name'];
      $tmp[$tmp_count]['no'] = $arr[$i]['no'];
      $tmp_count++;
    }

    if ( $next > $this->page_num )
    {
      $next = $this->page_num;
      $tmp[$tmp_count]['url'] = '';
      $tmp[$tmp_count]['name'] = "下一頁(yè)";
      $tmp[$tmp_count]['no'] = $next;
    }
    else
    {
      $tmp[$tmp_count]['url'] = str_replace( $param . '=0', $param . '=' . $next, $url );
      $tmp[$tmp_count]['name'] = "下一頁(yè)";
      $tmp[$tmp_count]['no'] = $next;
    }

    return $tmp;
  }
  
  // 附加首頁(yè)和尾頁(yè)
  function make_first_end_link( $arr, $act, $url, $param )
  {
    $tmp = array();

    $before = 1;
    $next = $this->page_num;

    if ( $act == 1 )
    {
      $before = 1;
      $tmp[0]['url'] = '';
      $tmp[0]['name'] = "首頁(yè)";
      $tmp[0]['no'] = $before;
    }
    else
    {
      $tmp[0]['url'] = str_replace( $param . '=0', $param . '=' . $before, $url );
      $tmp[0]['name'] = "首頁(yè)";
      $tmp[0]['no'] = $before;
    }

    $counts = sizeof( $arr );
    $tmp_count = sizeof( $tmp );
    for( $i = 0;$i < $counts;$i++ )
    {
      $tmp[$tmp_count]['url'] = $arr[$i]['url'];
      $tmp[$tmp_count]['name'] = $arr[$i]['name'];
      $tmp[$tmp_count]['no'] = $arr[$i]['no'];
      $tmp_count++;
    }

    if ( $act == $this->page_num )
    {
      $tmp[$tmp_count]['url'] = '';
      $tmp[$tmp_count]['name'] = "尾頁(yè)";
      $tmp[$tmp_count]['no'] = $next;
    }
    else
    {
      $tmp[$tmp_count]['url'] = str_replace( $param . '=0', $param . '=' . $next, $url );
      $tmp[$tmp_count]['name'] = "尾頁(yè)";
      $tmp[$tmp_count]['no'] = $next;
    }

    return $tmp;
  }
  
   
  /**
   * 帶上一頁(yè)<,下一頁(yè)>,省略號(hào)的分頁(yè)
   * @param int $total    記錄總條數(shù)
   * @param int $act_page    當(dāng)前頁(yè)碼
   * @param string $url    url
   * @param int $maxpageicon  最大顯示頁(yè)碼數(shù)
   * @param int $style    上一頁(yè),下一頁(yè)顯示樣式
   * @param string $param    url參數(shù)
   */
  function make_page_with_points( $total,$act_page,$url,$maxpageicon,$style,$param )
  {
    $page_num = $this->Calculation_Page_Num( $total );    //總頁(yè)數(shù)
    $arr_min_max = $this->Calculation_Min_Max( $act_page );    //最大頁(yè),最小頁(yè)  
    if($total==0)
    {
       return "";

    }
    if( $act_page > $page_num )
    {
      $act_page = $page_num+1;
      $page_num = $page_num+1;
    }
    
    switch ($style){
      case 1:
        $name_before = '前一頁(yè)';
        $name_next = '后一頁(yè)';
        break;
      case 2:
        $name_before = '<';
        $name_next = '>';
        break;
      case 3:
        $name_before = '<<';
        $name_next = '>>';
        break;
      default:
        $name_before = '上一頁(yè)';
        $name_next = '下一頁(yè)';
    }
    
    if (!eregi("([?|&]$param=)", $url)) {
      $url = strpos($url,"?")===false?$url."?":$url."&";
      $url = $url."$param=0";
    }
        
    // 用正則把url改成正規(guī)的
    $url = eregi_replace( $param . '=[0-9]+', $param . '=0', $url );
    $res = array();
    $no_before = $act_page-1;
    $no_next = $act_page+1;
    
    //總頁(yè)數(shù)如果小于等于初始化最大呈現(xiàn)頁(yè)數(shù)
    if ($page_num<= ($maxpageicon + 1))
    {
      //如果當(dāng)前頁(yè)數(shù)是首頁(yè) 上一頁(yè)無(wú)效
      if ($act_page == 1)  
      {
        $res[0]['url'] = '';
        $res[0]['name'] = $name_before;
        $res[0]['no'] = $no_before;
      }
      else      //上一頁(yè)有效
      {
        $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
        $res[0]['name'] = $name_before;
        $res[0]['no'] = $no_before; 
      }
      //循環(huán)添加頁(yè)碼
      $d = 1;
      for ($i = 1; $i <= $page_num; $i++)
      {
        if ($i != $act_page)
        {
          $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
          $res[$d]['name'] = $i;
          $res[$d]['no'] = $i;
        }
        else  //當(dāng)前頁(yè),頁(yè)碼
        {
          $res[$d]['url'] = '';
          $res[$d]['name'] = $i;
          $res[$d]['no'] = $i;
          $res[$d]['attr'] = 'current';
        }
        $d++;
      }
      $last_d = count($res);
      //判斷尾頁(yè)
      if($act_page == $page_num)  //下一頁(yè)無(wú)效
      {
        $res[$last_d]['url'] = '';
        $res[$last_d]['name'] = $name_next;
        $res[$last_d]['no'] = $no_next;    
      }
      else
      {
         $res[$last_d]['url'] = str_replace( $param . '=0', $param . '=' .($act_page + 1), $url );
        $res[$last_d]['name'] = $name_next;
        $res[$last_d]['no'] = $no_next;
      }
    }else if ($page_num > ($maxpageicon + 1))//如果總頁(yè)數(shù)滿足添加省略號(hào)
    { 
      if ($act_page <= $maxpageicon) //如果當(dāng)前頁(yè)小于等于初始化數(shù)目
      {
        //如果當(dāng)前頁(yè)數(shù)是首頁(yè) 上一頁(yè)無(wú)效
        if ($act_page == 1)  
        {
          $res[0]['url'] = '';
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
        }
        else      //上一頁(yè)有效
        {
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before; 
        }
        //循環(huán)添加頁(yè)碼
        $d = 1;
        for ($i = 1; $i <= $maxpageicon; $i++)
        {
          if ($i != $act_page)
          {
            $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
            $res[$d]['name'] = $i;
            $res[$d]['no'] = $i;
          }
          else  //當(dāng)前頁(yè),頁(yè)碼
          {
            $res[$d]['url'] = '';
            $res[$d]['name'] = $i;
            $res[$d]['no'] = $i;
            $res[$d]['attr'] = 'current';
          }
          $d++;
        }
        $last_d = count($res);
        //添加省略號(hào)
        $res[$last_d]['url'] = '';
        $res[$last_d]['name'] = '...';
        $res[$last_d]['no'] = '';
        //總頁(yè)數(shù)
        $res[$last_d+1]['url'] = str_replace( $param . '=0', $param . '=' . $page_num, $url );
        $res[$last_d+1]['name'] = $page_num;
        $res[$last_d+1]['no'] = $page_num;
        //下一頁(yè)
        $res[$last_d+1]['url'] = str_replace( $param . '=0', $param . '=' . ($act_page + 1), $url );
        $res[$last_d+1]['name'] = $name_next;
        $res[$last_d+1]['no'] = $no_next;     
      }else//如果當(dāng)前頁(yè)大于最大顯示頁(yè)面
      {
        if ($act_page > ($page_num - $maxpageicon))//滿足后幾頁(yè)
        {
          //上一頁(yè)
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
          //第一頁(yè)
          $res[1]['url'] = str_replace( $param . '=0', $param . '=1', $url );
          $res[1]['name'] = 1;
          $res[1]['no'] = 1;  
          //省略號(hào)
          $res[2]['url'] = '';
          $res[2]['name'] = '...';
          $res[2]['no'] = ''; 
          $d = 3;
          for ($i = ($page_num - $maxpageicon + 1); $i <= $page_num; $i++)
          {
            if ($i != $act_page)
            {
              $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
            }
            else  //當(dāng)前頁(yè),頁(yè)碼
            {
              $res[$d]['url'] = '';
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
              $res[$d]['attr'] = 'current';
            }
            $d++;
          }
          $last_d = count($res);
          //判斷尾頁(yè)
          if($act_page == $page_num)  //下一頁(yè)無(wú)效
          {
             $res[$last_d]['url'] = '';
            $res[$last_d]['name'] = $name_next;
            $res[$last_d]['no'] = $no_next;    
          }
          else
          {
             $res[$last_d]['url'] = str_replace( $param . '=0', $param . '=' .($act_page + 1), $url );
            $res[$last_d]['name'] = $name_next;
            $res[$last_d]['no'] = $no_next;
          }

        }else//滿足處在中間
        {
          //上一頁(yè)
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
          //第一頁(yè)
          $res[1]['url'] = str_replace( $param . '=0', $param . '=1', $url );
          $res[1]['name'] = 1;
          $res[1]['no'] = 1;  
          //省略號(hào)
          $res[2]['url'] = '';
          $res[2]['name'] = '...';
          $res[2]['no'] = ''; 
          for ($i = ($act_page - ($maxpageicon - 2) / 2); $i <= floor($act_page+($maxpageicon - 2) / 2); $i++)
          {
            $i = ceil($i);
            if ($i != $act_page)
            {
              $res[$d]['url'] = str_replace( $param . '=0', $param . '=' . $i, $url );
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
            }
            else  //當(dāng)前頁(yè),頁(yè)碼
            {
              $res[$d]['url'] = '';
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
              $res[$d]['attr'] = 'current';
            }
            $d++;
          }
          $last_d = count($res);
          //加省略號(hào)
          $res[$last_d]['url'] = '';
          $res[$last_d]['name'] = '...';
          $res[$last_d]['no'] = '';
          //當(dāng)前頁(yè)
          $res[$last_d+1]['url'] = str_replace( $param . '=0', $param . '=' . $page_num, $url );
          $res[$last_d+1]['name'] = $page_num;
          $res[$last_d+1]['no'] = $page_num;    
          //下一頁(yè)
          $res[$last_d+2]['url'] = str_replace( $param . '=0', $param . '=' . ($act_page + 1), $url );
          $res[$last_d+2]['name'] = $name_next;
          $res[$last_d+2]['no'] = $no_next;
          //exit;  
         }
      }
    }
    return $res;
  }
}

?>

以上就是為大家分享的兩款php分頁(yè)類(lèi),希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • PHP面向?qū)ο蟪绦蛟O(shè)計(jì)之接口用法

    PHP面向?qū)ο蟪绦蛟O(shè)計(jì)之接口用法

    這篇文章主要介紹了PHP面向?qū)ο蟪绦蛟O(shè)計(jì)的接口用法,對(duì)PHP程序設(shè)計(jì)人員來(lái)說(shuō)是有必要牢固掌握的概念,需要的朋友可以參考下
    2014-08-08
  • mac 下安裝php7全過(guò)程介紹

    mac 下安裝php7全過(guò)程介紹

    下面小編就為大家介紹一下mac 下安裝php7全過(guò)程。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • 修改Laravel5.3中的路由文件與路徑

    修改Laravel5.3中的路由文件與路徑

    本文先是回顧了Laravel5.2中路由的修改,然后給大家用實(shí)例代碼介紹了如何修改Laravel5.3中的路由,有需要的小伙伴們可以參考學(xué)習(xí)。
    2016-08-08
  • PHP實(shí)現(xiàn)的簡(jiǎn)單AES加密解密算法實(shí)例

    PHP實(shí)現(xiàn)的簡(jiǎn)單AES加密解密算法實(shí)例

    這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單AES加密解密算法,結(jié)合具體實(shí)例形式分析了php基于mcrypt_encrypt、bin2hex、mcrypt_decrypt等方法進(jìn)行字符串加密解密的相關(guān)操作技巧,需要的朋友可以參考下
    2017-05-05
  • PHP Post獲取不到非表單數(shù)據(jù)的問(wèn)題解決辦法

    PHP Post獲取不到非表單數(shù)據(jù)的問(wèn)題解決辦法

    這篇文章主要介紹了PHP Post獲取不到非表單數(shù)據(jù)的問(wèn)題的解決辦法以及代碼分享,需要的朋友參考下。
    2018-02-02
  • PHP連接MSSQL時(shí)nvarchar字段長(zhǎng)度被截?cái)酁?55的解決方法

    PHP連接MSSQL時(shí)nvarchar字段長(zhǎng)度被截?cái)酁?55的解決方法

    這篇文章主要介紹了PHP連接MSSQL時(shí)nvarchar字段長(zhǎng)度被截?cái)酁?55的解決方法,可通過(guò)CAST數(shù)據(jù)類(lèi)型轉(zhuǎn)換來(lái)解決,是非常實(shí)用的技巧,需要的朋友可以參考下
    2014-12-12
  • php 截取GBK文檔某個(gè)位置開(kāi)始的n個(gè)字符方法

    php 截取GBK文檔某個(gè)位置開(kāi)始的n個(gè)字符方法

    下面小編就為大家?guī)?lái)一篇php 截取GBK文檔某個(gè)位置開(kāi)始的n個(gè)字符方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • php實(shí)現(xiàn)簡(jiǎn)單的MVC框架實(shí)例

    php實(shí)現(xiàn)簡(jiǎn)單的MVC框架實(shí)例

    這篇文章主要介紹了php實(shí)現(xiàn)簡(jiǎn)單的MVC框架,較為詳細(xì)的分析了php實(shí)現(xiàn)MVC框架的相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • PHP $_FILES中error返回值詳解

    PHP $_FILES中error返回值詳解

    用PHP上傳文件時(shí),我們會(huì)用程序去監(jiān)聽(tīng)瀏覽器發(fā)送過(guò)來(lái)的文件信息,首先會(huì)通 過(guò)$_FILES[fieldName]['error']的不同數(shù)值來(lái)判斷此欲上傳的文件狀態(tài)是否正常。$_FILES[fieldName] ['error']==0代表一切正常,其它數(shù)值的具體含義請(qǐng)參考下面一段程序的注釋部分,如有翻譯不到之處還望指正
    2014-01-01
  • laravel 解決后端無(wú)法獲取到前端Post過(guò)來(lái)的值問(wèn)題

    laravel 解決后端無(wú)法獲取到前端Post過(guò)來(lái)的值問(wèn)題

    今天小編就為大家分享一篇laravel 解決后端無(wú)法獲取到前端Post過(guò)來(lái)的值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10

最新評(píng)論

科技| 怀柔区| 和田市| 鄂托克旗| 枝江市| 万宁市| 惠来县| 石阡县| 垫江县| 栾川县| 安义县| 包头市| 泾阳县| 肇庆市| 锦州市| 剑川县| 祁门县| 班玛县| 南靖县| 莱阳市| 德安县| 金寨县| 会同县| 乌海市| 包头市| 金溪县| 句容市| 宣威市| 汉中市| 苏尼特左旗| 阳曲县| 宣武区| 大洼县| 南投市| 罗田县| 紫阳县| 遂溪县| 伊宁县| 密云县| 江川县| 陇川县|