首页 > 编程技术 > php

Php经典分页源码

发布时间:2016-11-25 16:12

#*********************************************************
#文件名称: function.php
#功能描述: 新闻添加修改处理模块
#程序制作:留印(adleyliu)
#联系qq  :14339095
#联系邮箱:[email=adleyliu@163.com]adleyliu@163.com[/email]
#官方网站: [url=http://www.115000.com.cn]http://www.115000.com.cn[/url]
#copyright (c) 2007-2008 115000.com.cn all rights reserved.
#最后更新:     2007-11-20
#*********************************************************


#*********************************************************
#分页函数
#*********************************************************
function yl_list_page($pageurl,$rsnum,$pages,$pagecount,$pagesize
){
#url
#总记录
#总页数
#当前页码
#每页显示数
   //$pageurl='?';
   
$pcount $pages
;
   
$page_info '<div class=pagenum>'
;
   
$page_info .= '<div class=num>'

   if ((
$pcount 1) && ($pcount == $pagecount
) ){
       
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount-1).'>上一页</a>'
;
   }elseif ((
$pagecount != 1) && ($pcount != $pagecount
)){
      
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount-1).'>上一页</a>'
;
   }
      
$page_info .= '<a href = '.$pageurl.'page=1>页首</a>'
;
   if (
$pagecount 4
){
     
$page_info .= '<a href = '.$pageurl.'page=1>[1]</a><span class=dot>...</span>'
;
   }
   if (
$pcount $pagecount+2
){
       
$endpage $pagecount+2
;
   }else{
     
$endpage $pcount
;
   }
   for (
$n = ($pagecount-2); $n <= $endpage$n
++){
      if (!(
$n 1
)){
         if (
$n == intval($pagecount
)){
         
$page_info .= '<span class=normal>'.$n.'</span>'
;
     }else{
        
$page_info .= '<a href = '.$pageurl.'page='.$n.'>['.$n.']</a>'
;
     }
      }
   }
   if (
$pagecount+$pcount
){
       
$page_info .= '<span class=dot>...</span><a href='.$pageurl.'page='.$pcount.'>['.$pcount.']</a>'
;
   }
       
$page_info .= '<a href = '.$pageurl.'page='.$pcount.'>页尾</a>'
;
   if ((
$pagecount == 1) && ($pcount != $pagecount) && ($pcount != 0
)){
       
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount 1).'>下一页</a>'
;
   }else if ((
$pagecount != 1) && ($pcount != $pagecount
)){
       
$page_info .= '<a href = '.$pageurl.'page='.intval($pagecount 1).'>下一页</a>'
;
   }
       
$page_info .= '</div></div>'
;
   
$page_info .= '<div class=pagenum>'
;
   
$page_info .= '<div class=num><span class=normal> 共:'.$rsnum .'条/'.$pcount.'页 每页/'.$pagesize.'条</span></div>'
;
   
$page_info .= ' <div class=num>'
;
   
//echo '<form name=page action='.$pageurl.'>';
   
$page_info .= ' 转到'
;
   
$page_info .= '<input type=text name=page value=\'1\' class=login_left style=\'width:28px;height:18px;\'>'
;
   
$page_info .= '页<input type=submit name=submit3 class=login_submit style=\'width:28px;height:18px;padding-top:1px;\' onclick=document.myform.action.value=\'go\'> '
;
   
//echo '</form>';
   
$page_info .= '</div>'
;
   
$page_info .= '</div>'
;
      return 
$page_info
;
}


<?php
/**
 *
 *  计数器(v1.1.0)
 *
 *  Version : 1.1.0
 *  Author  : 村长
 *  PHP     : >4.3
 *  
 */
class 
Counter
{
    var 
$CountFolder
;
    var 
$countType
;
    var 
$showtype
;
    var 
$imgArray
;

    function 
Counter
()
    {
        
$this->countType 0
;
        
$this->showtype "GetCountByDay"
;
        
$this->imgArray 
= array();
        
$this->MakeCounter
();
    }

    function 
MakeCounter
()
    {
        
$this->CountFolder "log/".date("Ymd"
);
        if(!
is_dir($this->CountFolder
))
        {
            
mkdir($this->CountFolder,0777
);
        }
        
$this->_DoCount
();
    }

    
//Save data file
    
function _DoCount
()
    {
        
$file date("Ymd").ip2long($_SERVER['REMOTE_ADDR']).".txt"
;
        if(!
file_exists($this->CountFolder."/".$file
))
        {
            
$fp = @fopen($this->CountFolder."/".$file,"wb+"
);
            
//这里可以保存其他需要的日志记录
            
@fputs($fp,$_SERVER['REMOTE_ADDR'
]);
            @
fclose($fp
);
        }
    }

    
//获得指定时间的统计数据
    //默认为1天 0 为取所有
    
function GetCountByDay($day=1
)
    {
        
//今日的时间戳
        
$today strtotime(date("Y-m-d"
));
        
$all 0
;
        for(
$i=$day;$i>=0;$i
--)
        {
            
$tsp $today-(86400*$i
);
            
$folder "log/".date("Ymd",$tsp)."/*.txt"
;
            
$ta glob("$folder"
);
            
$all$allcount($ta
);
        }
        return 
$all
;
    }

    function 
GetCountUseImg($day=1
)    
    {
        
$allnumber $this->GetCountByDay($day
);
        for(
$i=0;$i<strlen($allnumber);$i
++)
        {
            
$idx substr($allnumber,$i,1
);
            
$returnVal.= sprintf("<img src=\"%s\">",$this->imgArray[$idx
]);
        }
        return 
$returnVal
;
    }    

    function 
SetStyle($style='',$ext="gif"
)
    {
        
$imgprefix ="img/"
;
        
$folder $imgprefix.$style
;
        foreach(
range(0,9) as $num
)
        {
            
$this->imgArray[$num] = $folder."/".$num.".$ext"
;
        }
        if(
is_dir($folder
))
        {
            
$this->showtype "GetCountUseImg"
;
        }
        else 
        {
            
$this->showtype "GetCountByDay"
;
        }
    }
    
    function 
Show($day=0
)
    {
        return 
$this->{$this->showtype}($day
);
    }
}

//实例计数器对象
$counter = new Counter
();

//采用 sports98 样式显示,告知默认扩展名为png格式
$counter->SetStyle("sports98","png"
);
echo 
"<br />今日访问:".$counter->Show(0
);

//采用S1样式显示,默认扩展名为 gif
$counter->SetStyle("s1"
);
echo 
"<br />近3日访问:".$counter->Show(2
);

//----只显示文字的计数器
$counter->SetStyle("-"
);
echo 
"<br />近3日访问:".$counter->Show(2
);
?>

// PHP 4.3 or above needed
define("BRIEF_LENGTH", 800);        //Word amount of the Briefing of an Article
function Generate_Brief($text){
    global $Briefing_Length;
    if(strlen($text) <= BRIEF_LENGTH ) return $text;    
    $Foremost = substr($text, 0, BRIEF_LENGTH);
    $re = "/<(\/?)(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|TABLE|TR|TD|TH|INPUT|SELECT|TEXTAREA|OBJECT|A|UL|OL|LI|BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|SPAN)[^>]*(>?)/i";
    $Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT/i";    
    
    $Stack = array(); $posStack = array();
    preg_match_all($re,$Foremost,$matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
    
    /*    [Child-matching Specification]:
        
        $matches[$i][1] : A "/" charactor indicating whether current "<...>" Friction is Closing Part
        $matches[$i][2] : Element Name.
        $matches[$i][3] : Right > of a "<...>" Friction    */
    for($i = 0 ; $i < count($matches); $i++){
        if($matches[$i][1][0] == ""){
            $Elem = $matches[$i][2][0];
            if(preg_match($Single,$Elem) && $matches[$i][3][0] !=""){
                continue;
            }
            array_push($Stack, strtoupper($matches[$i][2][0]));
            array_push($posStack, $matches[$i][2][1]);            
            if($matches[$i][3][0] =="") break;
        }else{
            $StackTop = $Stack[count($Stack)-1];
            $End = strtoupper($matches[$i][2][0]);
            if(strcasecmp($StackTop,$End)==0){
                array_pop($Stack);
                array_pop($posStack);
                if($matches[$i][3][0] ==""){
                    $Foremost = $Foremost.">";
                }
            }
        }        
    }
    $cutpos = array_shift($posStack) - 1;    
    $Foremost = substr($Foremost,0,$cutpos);
    return $Foremost;
};

正则表达式用于字符串处理、表单验证等场合,实用高效。现将一些常用的表达式收集于此,以备不时之需。

匹配中文字符的正则表达式: [\u4e00-\u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了

匹配双字节字符正则表达式(包括汉字在内):[^\x00-\xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

匹配空白行的正则表达式:\n\s*\r
评注:可以用来删除空白行

匹配HTML标记的正则表达式:<(\S*?)[^>]*>.*?</\1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力

匹配首尾空白字符的正则表达式:^\s*|\s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式

匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
评注:表单验证时很实用

匹配网址URL的正则表达式:[a-zA-z]+://[^\s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求

匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用

匹配国内电话号码:\d{3}-\d{8}|\d{4}-\d{7}
评注:匹配形式如 0511-4405222 或 021-87888822

匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始

匹配中国邮政编码:[1-9]\d{5}(?!\d)
评注:中国邮政编码为6位数字

匹配身份证:\d{15}|\d{18}
评注:中国的身份证为15位或18位

匹配ip地址正则表达式:\d+\.\d+\.\d+\.\d+
评注:提取ip地址时有用

匹配特定数字:
^[1-9]\d*$    //匹配正整数
^-[1-9]\d*$   //匹配负整数
^-?[1-9]\d*$   //匹配整数
^[1-9]\d*|0$  //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$   //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$   //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$  //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$  //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$   //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$  //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正

匹配特定字符串:
^[A-Za-z]+$  //匹配由26个英文字母组成的字符串
^[A-Z]+$  //匹配由26个英文字母的大写组成的字符串
^[a-z]+$  //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$  //匹配由数字和26个英文字母组成的字符串
^\w+$  //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式

mpmenu1=new mMenu('网站首页','/','self','','','','');
mpmenu1.addItem(new mMenuItem(' 用户注册','/register.asp','self',false,'用户注册',null,'','','',''));
mpmenu1.addItem(new mMenuItem(' 用户登录','/login.asp','self',false,'用户登录',null,'','','',''));
mpmenu1.addItem(new mMenuItem(' 用户退出','/login.asp?action=logout','self',false,'用户退出',null,'','','',''));
mpmenu1.addItem(new mMenuItem(' 资料修改','/bbs/MYMODIFY.ASP','self',false,'',null,'','','',''));
mpmenu2=new mMenu('软件下载','/SoftDown/','self','','','','');
mpmenu2.addItem(new mMenuItem(' 系统程序','/softdown/index.asp?CateID=1','self',false,'系统程序',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 网络工具','/softdown/index.asp?CateID=2','self',false,'网络工具',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 媒体工具','/softdown/index.asp?CateID=3','self',false,'媒体工具',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 图文处理','/softdown/index.asp?CateID=4','self',false,'图文处理',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 桌面工具','/softdown/index.asp?CateID=5','self',false,'桌面工具',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 程序代码','/softdown/index.asp?CateID=6','self',false,'程序代码',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 游戏娱乐','/softdown/index.asp?CateID=7','self',false,'游戏娱乐',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 其他工具','/softdown/index.asp?CateID=8','self',false,'其他工具',null,'','','',''));
mpmenu2.addItem(new mMenuItem(' 特别栏目','/softdown/index.asp?CateID=9','self',false,'特别栏目',null,'','','',''));
mpmenu2.addItem(new mMenuItem(null,null,null,true));
mpmenu2.addItem(new mMenuItem(' 下载排行','/SoftDown/Index.asp?order=AllHits&updown=desc','self',false,'软件下载排行榜',null,'','','',''));
mpmenu3=new mMenu('软件学院','/SoftSchool/','self','','','','');
mpmenu3.addItem(new mMenuItem(' 软件

标签:[!--infotagslink--]

您可能感兴趣的文章: