search
HomeBackend DevelopmentPHP Tutorialphp paging class_PHP tutorial
php paging class_PHP tutorialJul 20, 2016 am 11:15 AM
makemaxminpagephpPaginationkind

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

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

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

    <span var</span> <span $isNextPage</span> = <span true</span><span ;
    </span><span var</span> <span $isFirstPage</span> = <span false</span><span ;

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

    </span><span function</span> Calculation_Min_Max( <span $act_page</span> = 1<span  )
    {
        </span><span //</span><span  定义左右偏移量</span>
        <span $py_left</span> = 0<span ;
        </span><span $py_right</span> = 0<span ;
        </span><span //</span><span  定义左右边界</span>
        <span $bj_left</span> = 0<span ;
        </span><span $bj_right</span> = 0<span ;
        </span><span //</span><span  定义滚动区间边界</span>
        <span $gd_left</span> = 0<span ;
        </span><span $gd_right</span> = 0<span ;
        </span><span //</span><span  判断是否需要分组</span>
        <span if</span> ( ( <span $this</span>->page_num - <span $this</span>->page_max ) <= 0<span  )
        {
            </span><span //</span><span  不需要分组</span>
            <span $bj_left</span> = 1<span ;
            </span><span $bj_right</span> = <span $this</span>-><span page_num;
        }
        </span><span else</span><span 
        {
            </span><span //</span><span  要进行分组
            // 判断容量的奇偶</span>
            <span $tmp</span> = <span $this</span>->page_max % 2<span ;
            </span><span if</span> ( <span $tmp</span> === 1<span  )
            {
                </span><span //</span><span  奇数</span>
                <span $py_left</span> = <span $py_right</span> = ( <span $this</span>->page_max - 1 ) / 2<span ;
            }
            </span><span else</span><span 
            {
                </span><span //</span><span  偶数</span>
                <span $py_left</span> = <span $this</span>->page_max / 2 - 1<span ;
                </span><span $py_right</span> = <span $this</span>->page_max / 2<span ;
            }
            </span><span //</span><span  计算滚动区间</span>
            <span $gd_left</span> = 1 + <span $py_left</span><span ;
            </span><span $gd_right</span> = <span $this</span>->page_num - <span $py_right</span><span ;
            </span><span //</span><span  判断当前页是否落入了滚动区间</span>
            <span if</span> ( <span $act_page</span> >= <span $gd_left</span> && <span $act_page</span> <= <span $gd_right</span><span  )
            {
                </span><span //</span><span  区间内</span>
                <span $bj_left</span> = <span $act_page</span> - <span $py_left</span><span ;
                </span><span $bj_right</span> = <span $act_page</span> + <span $py_right</span><span ;
            }
            </span><span else</span><span 
            {
                </span><span //</span><span  区间外</span>
                <span if</span> ( ( <span $act_page</span> - <span $py_left</span> ) <= 1<span  )
                {
                    </span><span //</span><span  左侧固定区间</span>
                    <span $bj_left</span> = 1<span ;
                    </span><span $bj_right</span> = <span $this</span>-><span page_max;
                }
                </span><span else</span><span 
                {
                    </span><span $bj_left</span> = <span $this</span>->page_num - <span $this</span>->page_max + 1<span ;
                    </span><span $bj_right</span> = <span $this</span>-><span page_num;
                }
            }
        }

        </span><span $res</span> = <span array</span><span ();
        </span><span $res</span>['min'] = <span $bj_left</span><span ;
        </span><span $res</span>['max'] = <span $bj_right</span><span ;

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

        </span><span if</span> ( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span><span ;
        }
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );

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

        </span><span if</span> ( <span $this</span>-><span isNextPage )
        {
            </span><span $res</span> = <span $this</span>->make_before_next_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        </span><span if</span> ( <span $this</span>-><span isFirstPage )
        {
            </span><span $res</span> = <span $this</span>->make_first_end_link( <span $res</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  );
        }
        </span><span return</span> <span $res</span><span ;
    }
    </span><span //</span><span // 带总页数</span>
    <span function</span> make_page_with_total( <span $total</span>, <span $act_page</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $page_num</span> = <span $this</span>->Calculation_Page_Num( <span $total</span><span  );
        </span><span $arr_min_max</span> = <span $this</span>->Calculation_Min_Max( <span $act_page</span><span  );
        
        </span><span if</span> (!<span eregi</span>("([?|&]<span $param</span>=)", <span $url</span><span )) {
            </span><span $url</span> = <span strpos</span>(<span $url</span>,"?")===<span false</span>?<span $url</span>."?":<span $url</span>."&"<span ;
            </span><span $url</span> = <span $url</span>."<span $param</span>=0"<span ;
        }

        </span><span if</span> ( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span><span ;
        }
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );

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

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

        </span><span $before</span> = <span $act</span> - 1<span ;
        </span><span $next</span> = <span $act</span> + 1<span ;

        </span><span if</span> ( <span $before</span> < 1<span  )
        {
            </span><span $before</span> = 1<span ;
            </span><span $tmp</span>[0]['url'] = ''<span ;
            </span><span $tmp</span>[0]['name'] = "上一页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $before</span>, <span $url</span><span  );
            </span><span $tmp</span>[0]['name'] = "上一页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }

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

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

        </span><span return</span> <span $tmp</span><span ;
    }
    
    </span><span //</span><span  附加首页和尾页</span>
    <span function</span> make_first_end_link( <span $arr</span>, <span $act</span>, <span $url</span>, <span $param</span><span  )
    {
        </span><span $tmp</span> = <span array</span><span ();

        </span><span $before</span> = 1<span ;
        </span><span $next</span> = <span $this</span>-><span page_num;

        </span><span if</span> ( <span $act</span> == 1<span  )
        {
            </span><span $before</span> = 1<span ;
            </span><span $tmp</span>[0]['url'] = ''<span ;
            </span><span $tmp</span>[0]['name'] = "首页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }
        </span><span else</span><span 
        {
            </span><span $tmp</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $before</span>, <span $url</span><span  );
            </span><span $tmp</span>[0]['name'] = "首页"<span ;
            </span><span $tmp</span>[0]['no'] = <span $before</span><span ;
        }

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

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

        </span><span return</span> <span $tmp</span><span ;
    }
    
     
    </span><span /*</span><span *
     * 带上一页<,下一页>,省略号的分页
     * @param int $total        记录总条数
     * @param int $act_page        当前页码
     * @param string $url        url
     * @param int $maxpageicon    最大显示页码数
     * @param int $style        上一页,下一页显示样式
     * @param string $param        url参数
     </span><span */</span>
    <span function</span> make_page_with_points( <span $total</span>,<span $act_page</span>,<span $url</span>,<span $maxpageicon</span>,<span $style</span>,<span $param</span><span  )
    {
        </span><span $page_num</span> = <span $this</span>->Calculation_Page_Num( <span $total</span> );        <span //</span><span 总页数</span>
        <span $arr_min_max</span> = <span $this</span>->Calculation_Min_Max( <span $act_page</span> );        <span //</span><span 最大页,最小页    </span>
        <span if</span>(<span $total</span>==0<span )
        {
             </span><span return</span> ""<span ;

        }
        </span><span if</span>( <span $act_page</span> > <span $page_num</span><span  )
        {
            </span><span $act_page</span> = <span $page_num</span>+1<span ;
            </span><span $page_num</span> = <span $page_num</span>+1<span ;
        }
        
        </span><span switch</span> (<span $style</span><span ){
            </span><span case</span> 1:
                <span $name_before</span> = '前一页'<span ;
                </span><span $name_next</span> = '后一页'<span ;
                </span><span break</span><span ;
            </span><span case</span> 2:
                <span $name_before</span> = '<'<span ;
                </span><span $name_next</span> = '>'<span ;
                </span><span break</span><span ;
            </span><span case</span> 3:
                <span $name_before</span> = '<<'<span ;
                </span><span $name_next</span> = '>>'<span ;
                </span><span break</span><span ;
            </span><span default</span>:
                <span $name_before</span> = '上一页'<span ;
                </span><span $name_next</span> = '下一页'<span ;
        }
        
        </span><span if</span> (!<span eregi</span>("([?|&]<span $param</span>=)", <span $url</span><span )) {
            </span><span $url</span> = <span strpos</span>(<span $url</span>,"?")===<span false</span>?<span $url</span>."?":<span $url</span>."&"<span ;
            </span><span $url</span> = <span $url</span>."<span $param</span>=0"<span ;
        }
                
        </span><span //</span><span  用正则把url改成正规的</span>
        <span $url</span> = <span eregi_replace</span>( <span $param</span> . '=[0-9]+', <span $param</span> . '=0', <span $url</span><span  );
        </span><span $res</span> = <span array</span><span ();
        </span><span $no_before</span> = <span $act_page</span>-1<span ;
        </span><span $no_next</span> = <span $act_page</span>+1<span ;
        
        </span><span //</span><span 总页数如果小于等于初始化最大呈现页数</span>
        <span if</span> (<span $page_num</span><= (<span $maxpageicon</span> + 1<span ))
        {
            </span><span //</span><span 如果当前页数是首页  上一页无效</span>
            <span if</span> (<span $act_page</span> == 1<span )    
            {
                </span><span $res</span>[0]['url'] = ''<span ;
                </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
            }
            </span><span else</span>            <span //</span><span 上一页有效</span>
<span             {
                </span><span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                </span><span $res</span>[0]['no'] = <span $no_before</span><span ;  
            }
            </span><span //</span><span 循环添加页码</span>
            <span $d</span> = 1<span ;
            </span><span for</span> (<span $i</span> = 1; <span $i</span> <= <span $page_num</span>; <span $i</span>++<span )
            {
                </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                {
                    </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                    </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                }
                </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                 {
                    </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                    </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                    </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                }
                </span><span $d</span>++<span ;
            }
            </span><span $last_d</span> = <span count</span>(<span $res</span><span );
            </span><span //</span><span 判断尾页</span>
            <span if</span>(<span $act_page</span> == <span $page_num</span>)    <span //</span><span 下一页无效</span>
<span             {
                </span><span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;        
            }
            </span><span else</span><span 
            {
                  </span><span $res</span>[<span $last_d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> + 1), <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;
            }
        }</span><span else</span> <span if</span> (<span $page_num</span> > (<span $maxpageicon</span> + 1))<span //</span><span 如果总页数满足添加省略号</span>
<span         { 
            </span><span if</span> (<span $act_page</span> <= <span $maxpageicon</span>) <span //</span><span 如果当前页小于等于初始化数目</span>
<span             {
                </span><span //</span><span 如果当前页数是首页  上一页无效</span>
                <span if</span> (<span $act_page</span> == 1<span )    
                {
                    </span><span $res</span>[0]['url'] = ''<span ;
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                }
                </span><span else</span>            <span //</span><span 上一页有效</span>
<span                 {
                    </span><span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;  
                }
                </span><span //</span><span 循环添加页码</span>
                <span $d</span> = 1<span ;
                </span><span for</span> (<span $i</span> = 1; <span $i</span> <= <span $maxpageicon</span>; <span $i</span>++<span )
                {
                    </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                    {
                        </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                        </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                    }
                    </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                     {
                        </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                        </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                    }
                    </span><span $d</span>++<span ;
                }
                </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                </span><span //</span><span 添加省略号</span>
                <span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                </span><span $res</span>[<span $last_d</span>]['name'] = '...'<span ;
                </span><span $res</span>[<span $last_d</span>]['no'] = ''<span ;
                </span><span //</span><span 总页数</span>
                <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $page_num</span>, <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $page_num</span><span ;
                </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $page_num</span><span ;
                </span><span //</span><span 下一页</span>
                <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . (<span $act_page</span> + 1), <span $url</span><span  );
                </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $name_next</span><span ;
                </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $no_next</span><span ;         
            }</span><span else</span><span //</span><span 如果当前页大于最大显示页面</span>
<span             {
                </span><span if</span> (<span $act_page</span> > (<span $page_num</span> - <span $maxpageicon</span>))<span //</span><span 满足后几页</span>
<span                 {
                    </span><span //</span><span 上一页</span>
                    <span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                    </span><span //</span><span 第一页</span>
                    <span $res</span>[1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=1', <span $url</span><span  );
                    </span><span $res</span>[1]['name'] = 1<span ;
                    </span><span $res</span>[1]['no'] = 1<span ;   
                    </span><span //</span><span 省略号</span>
                    <span $res</span>[2]['url'] = ''<span ;
                    </span><span $res</span>[2]['name'] = '...'<span ;
                    </span><span $res</span>[2]['no'] = ''<span ;  
                    </span><span $d</span> = 3<span ;
                    </span><span for</span> (<span $i</span> = (<span $page_num</span> - <span $maxpageicon</span> + 1); <span $i</span> <= <span $page_num</span>; <span $i</span>++<span )
                    {
                        </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                        {
                            </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        }
                        </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                         {
                            </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                        }
                        </span><span $d</span>++<span ;
                    }
                    </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                    </span><span //</span><span 判断尾页</span>
                    <span if</span>(<span $act_page</span> == <span $page_num</span>)    <span //</span><span 下一页无效</span>
<span                     {
                          </span><span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                        </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                        </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;        
                    }
                    </span><span else</span><span 
                    {
                          </span><span $res</span>[<span $last_d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> + 1), <span $url</span><span  );
                        </span><span $res</span>[<span $last_d</span>]['name'] = <span $name_next</span><span ;
                        </span><span $res</span>[<span $last_d</span>]['no'] = <span $no_next</span><span ;
                    }

                }</span><span else</span><span //</span><span 满足处在中间</span>
<span                 {
                    </span><span //</span><span 上一页</span>
                    <span $res</span>[0]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' .(<span $act_page</span> - 1), <span $url</span><span  );
                    </span><span $res</span>[0]['name'] = <span $name_before</span><span ;
                    </span><span $res</span>[0]['no'] = <span $no_before</span><span ;
                    </span><span //</span><span 第一页</span>
                    <span $res</span>[1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=1', <span $url</span><span  );
                    </span><span $res</span>[1]['name'] = 1<span ;
                    </span><span $res</span>[1]['no'] = 1<span ;   
                    </span><span //</span><span 省略号</span>
                    <span $res</span>[2]['url'] = ''<span ;
                    </span><span $res</span>[2]['name'] = '...'<span ;
                    </span><span $res</span>[2]['no'] = ''<span ;  
                    </span><span for</span> (<span $i</span> = (<span $act_page</span> - (<span $maxpageicon</span> - 2) / 2); <span $i</span> <= <span floor</span>(<span $act_page</span>+(<span $maxpageicon</span> - 2) / 2); <span $i</span>++<span )
                    {
                        </span><span $i</span> = <span ceil</span>(<span $i</span><span );
                        </span><span if</span> (<span $i</span> != <span $act_page</span><span )
                        {
                            </span><span $res</span>[<span $d</span>]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $i</span>, <span $url</span><span  );
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                        }
                        </span><span else</span>    <span //</span><span 当前页,页码</span>
<span                         {
                            </span><span $res</span>[<span $d</span>]['url'] = ''<span ;
                            </span><span $res</span>[<span $d</span>]['name'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['no'] = <span $i</span><span ;
                            </span><span $res</span>[<span $d</span>]['attr'] = 'current'<span ;
                        }
                        </span><span $d</span>++<span ;
                   }
                    </span><span $last_d</span> = <span count</span>(<span $res</span><span );
                    </span><span //</span><span 加省略号</span>
                    <span $res</span>[<span $last_d</span>]['url'] = ''<span ;
                    </span><span $res</span>[<span $last_d</span>]['name'] = '...'<span ;
                    </span><span $res</span>[<span $last_d</span>]['no'] = ''<span ;
                    </span><span //</span><span 当前页</span>
                    <span $res</span>[<span $last_d</span>+1]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . <span $page_num</span>, <span $url</span><span  );
                    </span><span $res</span>[<span $last_d</span>+1]['name'] = <span $page_num</span><span ;
                    </span><span $res</span>[<span $last_d</span>+1]['no'] = <span $page_num</span><span ;        
                    </span><span //</span><span 下一页</span>
                    <span $res</span>[<span $last_d</span>+2]['url'] = <span str_replace</span>( <span $param</span> . '=0', <span $param</span> . '=' . (<span $act_page</span> + 1), <span $url</span><span  );
                    </span><span $res</span>[<span $last_d</span>+2]['name'] = <span $name_next</span><span ;
                    </span><span $res</span>[<span $last_d</span>+2]['no'] = <span $no_next</span><span ;
                    </span><span //</span><span exit;    </span>
<span                  }
            }
        }
        </span><span return</span> <span $res</span><span ;
    }
}

</span>?>

How to use:

<span $page_no</span> = <span $_GET</span>['page_no'] ? <span $_GET</span>['page_no'] : 1<span ;
</span><span $count</span> = 20<span ;
</span><span $start</span> = (<span $page_no</span>-1)*<span $count</span><span ;
</span><span $end</span> = <span $start</span> + <span $count</span><span ;
</span><span $page</span> = <span new</span><span  Page_Link();
</span><span $page</span>->length = <span $count</span><span ;
</span><span $page</span>->isFirstPage = <span true</span><span ;
</span><span $url</span> = <span $_SERVER</span>['SCRIPT_NAME']."?&a=".<span $a</span><span ;
</span><span $page_arr</span> = <span $page</span>->make_page(<span $total_num</span>,<span $page_no</span>,<span $url</span>,"page_no");

Supports multiple styles:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440232.htmlTechArticle? = 10; = 10; = 20; = = Calculation_Page_Num( -page_num = ( / - - Calculation_Min_Max( = 1 = 0 = 0 = 0 = 0 = 0 = 0 ( ( -page_num - -page_max ) = 0 = 1 = - = -page_max % 2 ( === 1 =...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),