分享好友 编程语言首页 频道列表

两款万能的php分页类

PHP教程  2015-11-15 10:580

本文为大家分享个超级好用、万能的php分页类,具体的实现代码如下

第一款php分页类

<php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 * 分页类
 * 使用方式:
 * $page = new Page();
 * $page->init(1000, 20);
 * $page->setNotActiveTemplate('<span> {a} </span>');
 * $page->setActiveTemplate('{a}');
 * echo $page->show();
 * 
 * 
 * @author 风居住的地方
 */
class Page {
  /**
   * 总条数
   */
  private $total;
  /**
   * 每页大小
   */
  private $pageSize;
  /**
   * 总页数
   */
  private $pageNum;
  /**
   * 当前页
   */
  private $page;
  /**
   * 地址
   */
  private $uri;
  /**
   * 分页变量
   */
  private $pageParam;
  /**
   * LIMIT XX,XX
   */
  private $limit;
  /**
   * 数字分页显示
   */
  private $listnum = 8;
  /**
   * 分页显示模板
   * 可用变量参数
   * {total}   总数据条数
   * {pagesize}  每页显示条数
   * {start}   本页开始条数
   * {end}    本页结束条数
   * {pagenum}  共有多少页
   * {frist}   首页
   * {pre}    上一页
   * {next}    下一页
   * {last}    尾页
   * {list}    数字分页
   * {goto}    跳转按钮
   */
  private $template = '<div><span>共有{total}条数据</span><span>每页显示{pagesize}条数据</span>,<span>本页{start}-{end}条数据</span><span>共有{pagenum}页</span><ul>{frist}{pre}{list}{next}{last}{goto}</ul></div>';
  /**
   * 当前选中的分页链接模板
   */
  private $activeTemplate = '<li class="active"><a href="javascript:;">{text}</a></li>';
  /**
   * 未选中的分页链接模板
   */
  private $notActiveTemplate = '<li><a href="{url}">{text}</a></li>';
  /**
   * 显示文本设置
   */
  private $config = array('frist' => '首页', 'pre' => '上一页', 'next' => '下一页', 'last' => '尾页');
  /**
   * 初始化
   * @param type $total    总条数
   * @param type $pageSize  每页大小
   * @param type $param    url附加参数
   * @param type $pageParam  分页变量
   */
  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();
  }
   
  /**
   * 设置分页模板
   * @param type $template  模板配置
   */
  public function setTemplate($template) {
    $this->template = $template;
  }
   
  /**
   * 设置选中分页模板
   * @param type $activeTemplate   模板配置
   */
  public function setActiveTemplate($activeTemplate) {
    $this->activeTemplate = $activeTemplate;
  }
 
  /**
   * 设置未选中分页模板
   * @param type $notActiveTemplate  模板配置
   */
  public function setNotActiveTemplate($notActiveTemplate) {
    $this->notActiveTemplate = $notActiveTemplate;
  }
 
  /**
   * 返回分页
   * @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起始数
   * @return type
   */
  public function getOffset() {
    return ($this->page - 1) * $this->pageSize;
  }
   
  /**
   * 设置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;
    }
  }
 
  /**
   * 初始化当前页
   * @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;
    }
  }
 
  /**
   * 本页开始条数
   * @return int
   */
  private function star() {
    if ($this->total == 0) {
      return 0;
    } else {
      return ($this->page - 1) * $this->pageSize + 1;
    }
  }
 
  /**
   * 本页结束条数
   * @return type
   */
  private function end() {
    return min($this->page * $this->pageSize, $this->total);
  }
 
  /**
   * 设置当前页大小
   * @return type
   */
  private function setPageSize() {
    return $this->end() - $this->star() + 1;
  }
   
  /**
   * 首页
   * @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;
  }
 
  /**
   * 上一页
   * @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;
  }
 
  /**
   * 分页数字列表
   * @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;
  }
 
  /**
   * 下一页
   * @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;
  }
 
  /**
   * 最后一页
   * @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;
  }
 
  /**
   * 跳转按钮
   * @return string
   */
  private function gopage() {
    $html = '';
    $html.=' <input type="text" value="' . $this->page . '" on
keydown="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   替换内容
   * @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分页类

<php
/*
 *本程序文件对分页程序进行了封装
 *
*/

class Page_Link
{
  var $page_max = 10; //一组页码的最大数

  var $page_num = 10; //总页数
  var $length = 20; //一页的数据条数

  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;
    // 定义滚动区间边界
    $gd_left = 0;
    $gd_right = 0;
    // 判断是否需要分组
    if ( ( $this->page_num - $this->page_max ) <= 0 )
    {
      // 不需要分组
      $bj_left = 1;
      $bj_right = $this->page_num;
    }
    else
    {
      // 要进行分组
      // 判断容量的奇偶
      $tmp = $this->page_max % 2;
      if ( $tmp === 1 )
      {
        // 奇数
        $py_left = $py_right = ( $this->page_max - 1 ) / 2;
      }
      else
      {
        // 偶数
        $py_left = $this->page_max / 2 - 1;
        $py_right = $this->page_max / 2;
      }
      // 计算滚动区间
      $gd_left = 1 + $py_left;
      $gd_right = $this->page_num - $py_right;
      // 判断当前页是否落入了滚动区间
      if ( $act_page >= $gd_left && $act_page <= $gd_right )
      {
        // 区间内
        $bj_left = $act_page - $py_left;
        $bj_right = $act_page + $py_right;
      }
      else
      {
        // 区间外
        if ( ( $act_page - $py_left ) <= 1 )
        {
          // 左侧固定区间
          $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改成正规的
    $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;
  }
  //// 带总页数
  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改成正规的
    $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;
  }
  
  // 附加上一页和下一页
  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'] = "上一页";
      $tmp[0]['no'] = $before;
    }
    else
    {
      $tmp[0]['url'] = str_replace( $param . '=0', $param . '=' . $before, $url );
      $tmp[0]['name'] = "上一页";
      $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'] = "下一页";
      $tmp[$tmp_count]['no'] = $next;
    }
    else
    {
      $tmp[$tmp_count]['url'] = str_replace( $param . '=0', $param . '=' . $next, $url );
      $tmp[$tmp_count]['name'] = "下一页";
      $tmp[$tmp_count]['no'] = $next;
    }

    return $tmp;
  }
  
  // 附加首页和尾页
  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'] = "首页";
      $tmp[0]['no'] = $before;
    }
    else
    {
      $tmp[0]['url'] = str_replace( $param . '=0', $param . '=' . $before, $url );
      $tmp[0]['name'] = "首页";
      $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'] = "尾页";
      $tmp[$tmp_count]['no'] = $next;
    }
    else
    {
      $tmp[$tmp_count]['url'] = str_replace( $param . '=0', $param . '=' . $next, $url );
      $tmp[$tmp_count]['name'] = "尾页";
      $tmp[$tmp_count]['no'] = $next;
    }

    return $tmp;
  }
  
   
  /**
   * 带上一页<,下一页>,省略号的分页
   * @param int $total    记录总条数
   * @param int $act_page    当前页码
   * @param string $url    url
   * @param int $maxpageicon  最大显示页码数
   * @param int $style    上一页,下一页显示样式
   * @param string $param    url参数
   */
  function make_page_with_points( $total,$act_page,$url,$maxpageicon,$style,$param )
  {
    $page_num = $this->Calculation_Page_Num( $total );    //总页数
    $arr_min_max = $this->Calculation_Min_Max( $act_page );    //最大页,最小页  
    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 = '前一页';
        $name_next = '后一页';
        break;
      case 2:
        $name_before = '<';
        $name_next = '>';
        break;
      case 3:
        $name_before = '<<';
        $name_next = '>>';
        break;
      default:
        $name_before = '上一页';
        $name_next = '下一页';
    }
    
    if (!eregi("([|&]$param=)", $url)) {
      $url = strpos($url,"")===false$url."":$url."&";
      $url = $url."$param=0";
    }
        
    // 用正则把url改成正规的
    $url = eregi_replace( $param . '=[0-9]+', $param . '=0', $url );
    $res = array();
    $no_before = $act_page-1;
    $no_next = $act_page+1;
    
    //总页数如果小于等于初始化最大呈现页数
    if ($page_num<= ($maxpageicon + 1))
    {
      //如果当前页数是首页 上一页无效
      if ($act_page == 1)  
      {
        $res[0]['url'] = '';
        $res[0]['name'] = $name_before;
        $res[0]['no'] = $no_before;
      }
      else      //上一页有效
      {
        $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
        $res[0]['name'] = $name_before;
        $res[0]['no'] = $no_before; 
      }
      //循环添加页码
      $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  //当前页,页码
        {
          $res[$d]['url'] = '';
          $res[$d]['name'] = $i;
          $res[$d]['no'] = $i;
          $res[$d]['attr'] = 'current';
        }
        $d++;
      }
      $last_d = count($res);
      //判断尾页
      if($act_page == $page_num)  //下一页无效
      {
        $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))//如果总页数满足添加省略号
    { 
      if ($act_page <= $maxpageicon) //如果当前页小于等于初始化数目
      {
        //如果当前页数是首页 上一页无效
        if ($act_page == 1)  
        {
          $res[0]['url'] = '';
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
        }
        else      //上一页有效
        {
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before; 
        }
        //循环添加页码
        $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  //当前页,页码
          {
            $res[$d]['url'] = '';
            $res[$d]['name'] = $i;
            $res[$d]['no'] = $i;
            $res[$d]['attr'] = 'current';
          }
          $d++;
        }
        $last_d = count($res);
        //添加省略号
        $res[$last_d]['url'] = '';
        $res[$last_d]['name'] = '...';
        $res[$last_d]['no'] = '';
        //总页数
        $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;
        //下一页
        $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//如果当前页大于最大显示页面
      {
        if ($act_page > ($page_num - $maxpageicon))//满足后几页
        {
          //上一页
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
          //第一页
          $res[1]['url'] = str_replace( $param . '=0', $param . '=1', $url );
          $res[1]['name'] = 1;
          $res[1]['no'] = 1;  
          //省略号
          $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  //当前页,页码
            {
              $res[$d]['url'] = '';
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
              $res[$d]['attr'] = 'current';
            }
            $d++;
          }
          $last_d = count($res);
          //判断尾页
          if($act_page == $page_num)  //下一页无效
          {
             $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//满足处在中间
        {
          //上一页
          $res[0]['url'] = str_replace( $param . '=0', $param . '=' .($act_page - 1), $url );
          $res[0]['name'] = $name_before;
          $res[0]['no'] = $no_before;
          //第一页
          $res[1]['url'] = str_replace( $param . '=0', $param . '=1', $url );
          $res[1]['name'] = 1;
          $res[1]['no'] = 1;  
          //省略号
          $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  //当前页,页码
            {
              $res[$d]['url'] = '';
              $res[$d]['name'] = $i;
              $res[$d]['no'] = $i;
              $res[$d]['attr'] = 'current';
            }
            $d++;
          }
          $last_d = count($res);
          //加省略号
          $res[$last_d]['url'] = '';
          $res[$last_d]['name'] = '...';
          $res[$last_d]['no'] = '';
          //当前页
          $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;    
          //下一页
          $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分页类,希望对大家的学习有所帮助。

查看更多关于【PHP教程】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
nginx和php-fpm 是使用 tcp socket 还是 unix socket ?
tcp socket允许通过网络进程之间的通信,也可以通过loopback进行本地进程之间通信。unix socket允许在本地运行的进程之间进行通信。分析从上面的图片可以看,unix socket减少了不必要的tcp开销,而tcp需要经过loopback,还要申请临时端口和tcp相关资源。但是

0评论2023-03-08437

PHP基于elasticsearch全文搜索引擎的开发 php使用es搜索引擎
1.概述:全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选。Elastic 的底层是开源库 Lucene。但是,你没法直接用 Lucene,必须自己写代码去调用它的接口。Elastic 是 Lucene 的封装,提供了 REST API 的操作接

0评论2023-02-09676

php视图操作
一、视图的基本介绍         视图是虚拟的表。与包含数据的表不一样,视图只包含使用时动态检索数据的查询。        使用视图需要MySQL5及以后的版本支持。        下面是视图的一些常见应用:        重用SQL语句;        简化复杂的S

0评论2023-02-09320

php使用时间戳保存时间的意义 PHP获取时间戳
时间戳记录的是格林尼治时间,使用date格式化的时候会根据你程序设置的不同时区显示不同的时间。如果使用具体时间,则还需要进行多一步转换。

0评论2023-02-09607

PHP 获取提交表单数据方法
PHP $_GET 和 $_POST变量是用来获取表单中的信息的,比如用户输入的信息。PHP表单操作在我们处理HTML表单和PHP表单时,我们要记住的重要一点是:HTML页面中的任何一个表单元素都可以自动的用于PHP脚本:表单举例: htmlbodyform action="welcome.php" method

0评论2023-02-09522

php中file_get_contents与curl的区别 php get file content
做微信开发的时候,项目中需要用PHP去请求微信相关接口。刚开始使用的是file_get_contents这个函数,后来听朋友说最好用curl。自己尝试了下,也能成功请求微信的接口。这两个有什么区别呢?抱着好奇心查阅了相关资料后,才知道他们之间确实有很大的不同。1.fo

0评论2023-02-09764

PHP与java接口对接使用json格式请求 php接收post数据json
PHP与java接口对接使用json格式请求$datajson = json_encode($param);$myheader= array('Content-Type: application/json; charset=utf-8','Content-Length: ' . strlen($datajson));$result = http_curl($url, 'xml', $datajson, 6, FALSE, ''

0评论2023-02-09566

PHP会员找回密码功能的简单实现 php密码登录验证
文章来自:博客http://www.jb51.net/article/91944.htm 设置思路1、用户注册时需要提供一个E-MAIL邮箱,目的就是用该邮箱找回密码。2、当用户忘记密码或用户名时,点击登录页面的“找回密码”超链接,打开表单,并输入注册用的E-MAIL邮箱,提交。3、系统通过

0评论2023-02-09488

php 判断一个变量是否是合法的json
1.场景api验证前端json 类型字段合法性2.分析官网3.解决function json_validate($string) {if (is_string($string)) {@json_decode($string);return (json_last_error() === JSON_ERROR_NONE);}return false;} 

0评论2023-02-09411

Apache 的 php.ini 配置文件详解
[root@taokey ~]# grep -v ";" /application/php/lib/php.ini  [PHP]  engine = On  ——→  是否启用 PHP 解析引擎  short_open_tag = Off    ——→  是否使用简介标志  asp_tags = Off  ——→  不允许 asp 类标志  precision = 14  —

0评论2023-02-09716

PHP的几种输出方式 php输出格式
请写出echo、print_r、print、var_dump 、die之间的区别   echo  只能输出字符串等单一数据 不能输出数据类型 不能输出数组等多种数据   print()  只能输出字符串等单一数据 不能输出数据类型 不能输出数组等多种数据有返回值true/false   print_r()

0评论2023-02-09753

建设银行网上银行MD5withRSA php版
1. 首先通过java程序将建设银行的公钥串转成pem格式并写入文件SignTest.java是运行程序, RSASig.java是建设银行签名算法类, bcprov-jdk15-145.jar是PEMWriter类库 2. php程序做签名验证?php$data = "POSID=000000000BRANCHID=330000000ORDERID=2004010061P

0评论2023-02-09605

php服务器删除浏览器cookie php清除浏览器缓存
一、设置cookie的过期时间//将过期时间设为一小时前setcookie("TestCookie", "", time() - 3600);setcookie("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1);二、设置cookie的值为空setcookie($cookiename, ''

0评论2023-02-09874

Docker-用LaraDock搭建PHP环境 docker搭建php开发环境
简介LaraDock 致力于简化创建开发环境过程,能够帮助我们在 Docker 上快速搭建 PHP 开发环境。 它预装了 Docker 镜像,为我们提供了一站式的开发环境,而不需要再去在本地机器安装 PHP、Nginx、MySQL 以及其他很多开发过程中需要的软件。特点:在 PHP 版本:7

0评论2023-02-09851

更多推荐