42 12
发新话题
打印

[转载]PHP类收集整理(持续更新)

[转载]PHP类收集整理(持续更新)

信息来源:天下第七收集整理

前面的话:这里收集整理一些php的类,我尽量吧我能看到的都收集过来。希望又对你又用的东西

名称: Progress_bar
大小: 1.91 KB
作者:Chris Geisler
来源:PHPClasses

详细介绍:
如果你的一段程序需要很长时间才能完成,在这段时间内又不想让你的客户等得不耐烦。那么 Progress_bar 可以帮你做到。

Process_bar 利用java script动态生成一个进度条,并且会根据你的任务进度来实时改变进度条的进度。

附件

progress_bar.zip (2 KB)

2006-3-27 03:48, 下载次数: 124

曾因酒醉鞭名马 生怕情多累美人

TOP

分页类:
复制内容到剪贴板
代码:
<?php
//
// +----------------------------------------------------------------------+
// | 分页类                                          |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 NetFish Software                       |
// |                                               |
// | Author: whxbb([email]whxbbh@21cn.com[/email])                          |
// +----------------------------------------------------------------------+
//
// $Id: pager.class.php,v 0.1 2001/8/2 13:18:13 yf Exp $
//
// 禁止直接访问该页面
if (basename($HTTP_SERVER_VARS[&#39;PHP_SELF&#39;]) == "pager.class.php") {
   header("HTTP/1.0 404 Not Found");
}
/**
* 分页类
* Purpose
* 分页
*
* @author  : whxbb([email]whxbb@21cn.com[/email])
* @version : 0.1
* @date   :  2001/8/2
*/
class Pager
{
   /** 总信息数 */
   var $infoCount;
   /** 总页数 */
   var $pageCount;
   /** 每页显示条数 */
   var $items;
   /** 当前页码 */
   var $pageNo;
   /** 查询的起始位置 */
   var $startPos;
   var $nextPageNo;
   var $prevPageNo;
   
   function Pager($infoCount, $items, $pageNo)
   {
      $this->infoCount = $infoCount;
      $this->items    = $items;
      $this->pageNo   = $pageNo;
      $this->pageCount = $this->GetPageCount();
      $this->AdjustPageNo();
      $this->startPos  = $this->GetStartPos();
   }
   function AdjustPageNo()
   {
      if($this->pageNo == &#39;&#39; || $this->pageNo < 1)
        $this->pageNo = 1;
      if ($this->pageNo > $this->pageCount)
        $this->pageNo = $this->pageCount;
   }
   /**
    * 下一页
    */
   function GoToNextPage()
   {
      $nextPageNo = $this->pageNo + 1;
      if ($nextPageNo > $this->pageCount)
      {
        $this->nextPageNo = $this->pageCount;
        return false;
      }
      $this->nextPageNo = $nextPageNo;
      return true;
   }
   /**
    * 上一页
    */
   function GotoPrevPage()
   {
      $prevPageNo = $this->pageNo - 1;
      if ($prevPageNo < 1)
      {
        $this->prevPageNo = 1;
        return false;
      }
      $this->prevPageNo = $prevPageNo;
      return true;
   }
   function GetPageCount()
   {
      return ceil($this->infoCount / $this->items);
   }
   function GetStartPos()
   {
      return ($this->pageNo - 1)  * $this->items;
   }
}
?>
曾因酒醉鞭名马 生怕情多累美人

TOP

目录操作基类
复制内容到剪贴板
代码:
<?
//目录操作基类
class FileDirectory {
  var $servermode;
  var $serverpath;   //web服务器目录
  var $pagepath;   //当前页目录
  var $path;      //当前目录
  var $ffblk;      //用于存储有关文件的信息
  function FileDirectory() {
   set_time_limit(0);   //设置网页运行时间,0不限
   $this->serverpath = $GLOBALS[DOCUMENT_ROOT]."/";
   $this->path = $this->pagepath = dirname(eregi_replace("//","/",$GLOBALS[SCRIPT_FILENAME]))."/";
   if(eregi("Win32",getenv("SERVER_SOFTWARE")))
    $this->servermode = "WIN32";
  }
  function first_dir() {
   return dirname(eregi_replace("//","/",$GLOBALS[SCRIPT_FILENAME]));
  }
  //获取文件信息
  function file_info($filename) {
   $ar[name] = $filename;
   $ar[type] = filetype($filename);
   $ar[read] = is_readable($filename);
   $ar[write] = is_writeable($filename);
   $ar[exec] = is_executable($filename);
   $ar[time] = date("Y-m-d H:i:s",filemtime($filename));
   $ar[size] = filesize($filename);
   $ar[style] = ($ar[type]=="dir"?"d":"-")
          .($ar[read]?"r":"-")
          .($ar[write]?"w":"-")
          .($ar[exec]?"x":"-");
   return $ar;
  }

  function format_path($path){
   $tar = split("/",$path);
   $sar = split("/",$this->path);
   $t = count($tar);
   $s = count($sar);
   if($tar[$t-1] == "") $t--;
   if($sar[$s-1] == "") $s--;
   $j = 0;
   while($tar[$j] == "..") {
    $j++;
    $s--;
   }
   $p = "";
   for($i=0;$i<$s;$i++)
    $p .= $sar[$i]."/";
   for($i=$j;$i<$t;$i++)
    if($tar[$i] != ".")
      $p .= $tar[$i]."/";
   $this->path = $p;
  }
  //获取目录信息到数组,成功返回时$this->path为目录的全路径
  function array_dir($pathname=".") {
   $old = $this->path;
   if($this->servermode == "WIN32")
    $path = str_replace("\\","/",$pathname);
   else
    $path = $pathname;
   $this->format_path($path);
   if(! ($handle = @opendir($path))) {
    $path = dirname($pathname);
    $handle = opendir($path);
   }
   if(@chdir($this->path)) {
    while ($file = readdir($handle)) {
      $ar[] = $this->file_info($file);
    }
   }else
    $this->path = $old;
   closedir($handle);
   return $ar;
  }
}   //FileDirectory定义结束

?>

<?
//目录对话框
class OpenFileDialog extends FileDirectory {
  var $filter = array("*.*");
  function Execute($path,$statpath) {
   if($path != "") {
    chdir($statpath);
    $this->path = $statpath;
    $ar = $this->array_dir($path);
   }else
    $ar = $this->array_dir(".");
   array_multisort($ar);
echo "
<style>
td{font-size:9pt;}
select{font-size:9pt;}
#box{border:3px outset #ffffff}
</style>
<form action=";
echo $GLOBALS[PHP_SELF];
echo " method=POST>
<table bgcolor=#cccccc cellspacing=0 cellpadding=0>
<tr><td>
<table border=0 id=box>
<tr><td>
";
echo "当前路径 ".$this->path."<br>\n";
echo "<input type=hidden name=statpath value=\"".$this->path."\">\n";

echo "<select name=dirlist size=6 style=\"width:100px\" onChange=\"this.form.submit()\">\n";
for($i=0;$i<count($ar);$i++)
  if($ar[$i][type] == "dir")
   if($ar[$i][name] == ".")
    echo "<option selected>".$ar[$i][name]."\n";
   else
    echo "<option>".$ar[$i][name]."\n";
echo "</select>  \n";
echo "<select size=6 style=\"width:100px\">\n";
for($i=0;$i<count($ar);$i++)
  if($ar[$i][type] == "file")
   echo "<option>".$ar[$i][name]."\n";
echo "
</select>
</td></tr>
</table>
</td></tr>
</table>
</form>
";
  }
}   //OpenFileDialog
?>

<?
//测试

$dir = new OpenFileDialog();
echo "服务器类型 ".$dir->servermode."<br>";
echo "服务器路径 ".$dir->serverpath."<br>";
echo "当前页路径 ".$dir->pagepath."<br>";
echo "当前路径 ".$dir->path."<br>";
$dir->Execute($dirlist,$statpath);
?>
曾因酒醉鞭名马 生怕情多累美人

TOP

日历类
复制内容到剪贴板
代码:
<?php
class Calendar{

/*
  *        日历
  *
  *    @作者:sports98
  *    Email:flyruns@hotmail.com
  *    @版本:V1.0
  */

   var $YEAR,$MONTH,$DAY;
   var $WEEK=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
   var $_MONTH=array(
        "01"=>"一月",
        "02"=>"二月",
        "03"=>"三月",
        "04"=>"四月",
        "05"=>"五月",
        "06"=>"六月",
        "07"=>"七月",
        "08"=>"八月",
        "09"=>"九月",
        "10"=>"十月",
        "11"=>"十一月",
        "12"=>"十二月"
      );

   //设置年份
   function setYear($year){
      $this->YEAR=$year;
   }
   //获得年份
   function getYear(){
      return $this->YEAR;
   }
   //设置月份
   function setMonth($month){
      $this->MONTH=$month;
   }
   //获得月份
   function getMonth(){
      return $this->MONTH;
   }
   //设置日期
   function setDay($day){
      $this->DAY=$day;
   }
   //获得日期
   function getDay(){
      return $this->DAY;
   }
   //打印日历
   function OUT(){
      $this->_env();
      $week=$this->getWeek($this->YEAR,$this->MONTH,$this->DAY);//获得日期为星期几 (例如今天为2003-07-18,星期五)
      $fweek=$this->getWeek($this->YEAR,$this->MONTH,1);//获得此月第一天为星期几
      echo "<div style=\"margin:0;border:1 solid black;width:300;font:9pt\">
        <form action=$_SERVER[PHP_SELF] method=\"post\" style=\"margin:0\">
        <select name=\"month\" onchange=\"this.form.submit();\">";

      for($ttmpa=1;$ttmpa<13;$ttmpa++){//打印12个月
        $ttmpb=sprintf("%02d",$ttmpa);
        if(strcmp($ttmpb,$this->MONTH)==0){
           $select="selected style=\"background-color:#c0c0c0\"";
        }else{
           $select="";
        }
        echo "<option value=\"$ttmpb\" $select>".$this->_MONTH[$ttmpb]."</option>\r\n";
      }

      echo "   </select> <select name=\"year\" onchange=\"this.form.submit();\">";//打印年份,前后10年
      for($ctmpa=$this->YEAR-10;$ctmpa<$this->YEAR+10;$ctmpa++){
        if($ctmpa>2037){
           break;
        }
        if($ctmpa<1970){
           continue;
        }
        if(strcmp($ctmpa,$this->YEAR)==0){
           $select="selected style=\"background-color:#c0c0c0\"";
        }else{
           $select="";
        }
        echo "<option value=\"$ctmpa\" $select>$ctmpa</option>\r\n";
      }
      echo    "</select>
        </form>
        <table border=0 align=center>";
      for($Tmpa=0;$Tmpa<count($this->WEEK);$Tmpa++){//打印星期标头
        echo "<td>".$this->WEEK[$Tmpa];
      }
      for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++){//打印所有日期
        if(strcmp($Tmpb,$this->DAY)==0){   //获得当前日期,做标记
           $flag=" bgcolor=&#39;#ff0000&#39;";
        }else{
           $flag=&#39; bgcolor=#ffffff&#39;;
        }
        if($Tmpb==1){      
           echo "<tr>";      //补充打印
           for($Tmpc=0;$Tmpc<$fweek;$Tmpc++){
              echo "<td>";
           }
        }
        if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0){
           echo "<tr><td align=center $flag>$Tmpb";
        }else{
           echo "<td align=center $flag>$Tmpb";
        }
      }
      echo "</table></div>";
   }
   //获得方法内指定的日期的星期数
   function getWeek($year,$month,$day){
      $week=date("w",mktime(0,0,0,$month,$day,$year));//获得星期
      return $week;//获得星期
   }

   function _env(){
      if(isset($_POST[month])){   //有指定月
        $month=$_POST[month];
      }else{
        $month=date("m");   //默认为本月
      }
      if(isset($_POST[year])){   //有指年
        $year=$_POST[year];
      }else{
        $year=date("Y");   //默认为本年
      }
   $this->setYear($year);
   $this->setMonth($month);
   $this->setDay(date("d"));

   }
}

$D=new Calendar;
$D->OUT();
?>
曾因酒醉鞭名马 生怕情多累美人

TOP

名称: Ziplib
大小: 7.57 KB
作者:bouchon

详细介绍:
  Ziplib 是一个用来建立、操作、控制 ZIP 文件的类。它看起来很小(11K),但是你可别小看了它,这个类的所有操作不需要 PHP 中ZLib 模板的支持。是的,你没有听错,这个类完全从底层控制了 ZIP 文件的读写!!! 这意味着你可以在任意一个主机上来操作你的 ZIP 文件。内附详细操作说明。Enjoy It!!

附件

ziplib.zip (8 KB)

2006-3-27 03:55, 下载次数: 76

曾因酒醉鞭名马 生怕情多累美人

TOP

简介:
  一个PHP文本数据表类

名称: Text_data
大小: 2.86 KB
作者:memstone
来源:CSDN


详细介绍:
  CSDN的一位朋友贡献的,希望对那些空间不支持Mysql数据库的朋友有点用途。

附件

text_data.rar (3 KB)

2006-3-27 03:57, 下载次数: 63

曾因酒醉鞭名马 生怕情多累美人

TOP

购物车的类,只用了一个Session
复制内容到剪贴板
代码:
<?php
class cart {

  var $sortCount; //商品种类数
  var $totalCost; //商品总金额
  /* 所有的商品,如:$myCart[5][$name]:商品编号为5的名称
  *          $myCart[5][$price]:商品编号为5的单价
  *         $myCart[5][$count]:商品编号为5的数量
  *          $myCart[5][$cost]:商品编号为5的合计金额
  */
  var $myCart   ;  
  var $Id;      //每类商品的ID(数组)
  var $Name;      //每类商品的名称(数组)
  var $Price;      //每类商品的价格(数组)
  var $Count;      //每类商品的件数(数组)
  var $Cost;      //每类商品的价值(数组)

  
  //******构造函数
  function cart(){
   $this->sortCount = 0   ;
   $this->totalCost = 0   ;
   $this->myCart   = array()   ;
   session_start();   //初始化一个session
   if(session_is_registered("myCart")==false)   session_register(&#39;myCart&#39;);     
   $this->update();
  //  $this->Calculate();
   
  }
  
  //********私有,根据session的值更新类中相应数据
  function update(){
   session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   if(false==$myCart)
   {
      $this->sortCount = 0   ;
      $this->totalCost = 0   ;
      $this->myCart = array()   ;
      return false;
   }
   //得到商品的总数量
   $this->sortCount=count($myCart);
   if($this->sortCount>0)
   {
      //开始计算商品的金额
      $totalCost = 0   ;
      foreach($myCart as $key=>$val)
      {
        //先四舍五入
        foreach($val as $proName=>$proVal)
        {
           if($proName !="name")
           {
              $val[$proName] = round(eregi_replace(",", "",$proVal),2)   ;
              $myCart[$key][$proName] = $val[$proName]   ;
           }
        }
           
        //计算每件商品的金额
        $myCart[$key]["cost"] = round($val["count"]*$val["price"], 2)   ;
        //得到所有商品的金额
        $totalCost += $myCart[$key]["cost"]   ;        
      }
      $this->totalCost = $totalCost   ;
      $this->myCart = $myCart        ;
      $_SESSION["myCart"] = $myCart   ;

   }
   
  }
  
/**
* 格式化数字为货币数据
*
*
**/
  function formatNum($data)
  {
   foreach($data as $key=>$val)
   {
      foreach($val as $sName=>$sValue)
      {
        if($sName !="name")
        {   
           $data[$key][$sName] = number_format($sValue, 2)   ;
        }
      }
   }
   return $data   ;

  }
//**************以下为接口函数
  
//*** 加一件商品
// 判断是否蓝中已有,如有,加count,否则加一个新商品
//首先都是改session的值,然后再调用update() and calculate()来更新成员变量
  function addOne($id,$na,$pr)
  {
   session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   //设置购物车中的数量
   $myCart[$id]["name"]  = $na   ;
   $myCart[$id]["price"] = $pr   ;
   ++$myCart[$id]["count"]   ;
   $_SESSION["myCart"] = $myCart   ;
   //更新一下类的成员数据
   $this->update();   

  }
/**
* 向购物车中添加一组商品,如果没有,进行添加,如果已经存在,则更新为data
* @param $data  - 要添加的商品,格式为:
*            $data[0][id],  $data[0][name],
*            $data[0][price],$data[0][count]
* @return boolean
*/
function addData($data)
{
   if(count($data > 0))  
   {
      session_start();   //初始化一个session
      $myCart = $_SESSION["myCart"]      ;
      foreach($data as $val)
      {
        extract($val)   ;
        //设置购物车中的数量
        $myCart[$id]["name"]  = $name   ;
        $myCart[$id]["price"] = $price   ;
        $myCart[$id]["count"] = $count   ;
      }
      $_SESSION["myCart"] = $myCart   ;
      //更新一下类的成员数据
      $this->update();   
   }
}
/*
* 更改一件商品的单价
*
*
*
**/
function updatePrice($id, $price)
{
   if($price <=0)   return false   ;
   session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   if($myCart[$id]==true)
   {
      $myCart[$id]["price"]=$price;

        $_SESSION["myCart"] = $myCart   ;
      $this->update();
   }
}
//将一件商品的数量减1
  function removeOne($id)
  {
    $count = $this->myCart[$id]["count"]   ;
    if($count>0)
    {
       $this->modifyCount($id, --$count)   ;
    }
  
  }
  
  //改变商品的个数,如果传入单价,则一起更改单价
  function modifyCount($id, $ncount, $price=0)
  {
   if($ncount <= 0) return false   ;
   session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   if($myCart[$id]==true)
   {
      $myCart[$id]["count"]=$ncount;
      //如果有传入单价,则一起更改单价
      if($price >0 ) $myCart[$id]["price"]=$price;

        $_SESSION["myCart"] = $myCart   ;
      $this->update();
   }
  
  }
  
  //清空一种商品
  function emptyOne($i)
  {
   session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   unset($myCart[$i])   ;
   if(count($myCart)==0)
   {
      $this->emptyAll()   ;
   }else{
      $_SESSION["myCart"] = $myCart      ;  
      $this->update();
   }
  }
  
  
  /***************************
  清空所有的商品
  
  因为在win里PHP不支持session_destroy()函数,所以这个清空函数不完善,
  只是把每种商品的个数置为0。
  如果是在linux下,可以直接用session_destroy()来做。
  *****************************/
  function emptyAll()
  {
     session_start();   //初始化一个session
   $myCart = $_SESSION["myCart"]      ;
   
   unset($myCart)   ;
   $_SESSION["myCart"] = $myCart      ;  
   $this->update();
   
  }
  
  /**
  *  返回所有购物车中的数据
  *
  **/
  function getData()
  {
    if($this->sortCount > 0)
    {
       return $this->myCart   ;
    }else{
       return array()   ;
    }
  }
  //取一件商品的信息,主要的工作函数
  //返回一个关联数组,下标分别对应 id,name,price,count,cost
  function getOne($i){
   $data = $this->myCart[$i]      ;
   if(false==$data) return array()   ;

   $data["id"]   =   $i           ;
   return $data                ;

  }
  
  //取总的商品种类数
  function getSortCount(){
   return $this->sortCount;
  }
  
  //取总的商品价值
  function getTotalCost(){
   return $this->totalCost;
  }
  
//end class  
}

?>

曾因酒醉鞭名马 生怕情多累美人

TOP

odbc连mssql分页的类
复制内容到剪贴板
代码:
<?
class Pages{
   var $cn;      //连接数据库游标
   var $d;        //连接数据表的游标
   var $result;   //结果
   var $dsn;      //dsn源
   var $user;      //用户名   
   var $pass;      //密码
   
   var $total;      //记录总数
   var $pages;      //总页数
   var $onepage;   //每页条数
   var $page;      //当前页
   var $fre;      //上一页
   var $net;      //下一页
   var $i;       //控制每页显示

   ##############################
   ########  连接数据库 ##########
   function getConnect($dsn,$user,$pass){
      $this->cn=@odbc_connect($dsn,$user,$pass);
      if(!$this->cn){
        $error="连接数据库出错";
        $this->getMess($error);
      }
   }

   ##############################
    ######## 进行表的查询 #########
   function getDo($sql){      //从表中查询数据
      $this->d=@odbc_do($this->cn,$sql);
      if(!$this->d){
        $error="查询时发生了小错误......";
        $this->getMess($error);
      }
      return $this->d;
   }
  
     #################################
    ######## 求表中数据的总量 #########
   function getTotal($sql){
      $this->sql=$sql;
      $dT=$this->getDo($this->sql);      //求总数的游标
      $this->total=odbc_result($dT,"total");      //这里为何不能$this->d,total 为一个字段
      //   $this->total=@odbc_num_rows($dT);      //应唠叨老大的意见,odbc_num_rows 不能用,不知为何,返回为-1
      return $this->total;
   }

   ##############################
   ######## 进行表的查询 #########
   function getList($sql,$onepage,$page){
      if ($page<>"" and $page<1)      //当此页小于时的处理
        $page=1;
      $this->s=$sql;
      $this->onepage=$onepage;      //每页显示的记录数
      $this->page=$page;      //页数
      $this->dList=$this->getDo($this->s);    //连接表的游标
      $this->pages=ceil($this->total/$this->onepage);    //计算大于指定数的最小整数
      if ($this->page>$this->pages)       //当此页大于最大页的处理
        $this->page=$this->pages;
      if($this->pages==0)
        $this->pages++;      //不能取到第0页
      if(!isset($this->page))
        $this->page=1;
      $this->fre = $this->page-1;    //将显示的页数
      $this->nxt = $this->page+1;
      $this->nums=($this->page-1)*$this->onepage;
      return $this->dList;
   }
   
   ##############################
   function getfetch_row($dList){
      return odbc_fetch_row($dList);
   }  

     ##############################
   function getresult($dList,$num){
      return odbc_result($dList,$num);
   }   
   ##############################
   ######## 翻页 ################
   function getFanye(){
      $str="";
      if($this->page!=1)
        $str.="<form name=go2to form method=Post action=&#39;".$PHP_SELF."&#39;><a href=".$PHP_SELF."?page=1> 首页 </a><a href=".$PHP_SELF."?page=".$this->fre."> 前页 </a>";
      else
        $str.="<font color=999999>首页 前页</font>";
      if($this->page<$this->pages)
        $str.="<a href=".$PHP_SELF."?page=".$this->nxt."> 后页 </a>";
      else
        $str.="<font color=999999> 后页 </font>";
      if($this->page!=$this->pages)
        $str.="<a href=".$PHP_SELF."?page=".$this->pages."> 尾页 </a>";
      else
        $str.="<font color=999999> 尾页 </font>";
      
      $str.="共".$this->pages."页";
      $str.="<font color=&#39;000064&#39;>  转到 第<input type=&#39;text&#39; name=&#39;page&#39; size=2 maxLength=3 style=&#39;font-size: 9pt; color:#00006A; position: relative; height: 18&#39; value=".$this->page.">页</font> ";
      $str.="<input class=button type=&#39;button&#39; value=&#39;确 定&#39; onclick=check() style=&#39;font-family: 宋体; font-size: 9pt; color: #000073; position: relative; height: 19&#39;></form>";
      return $str;
   }
   
   ####################################
   ######## 对进行提交表单的验验 #########
   function check()
   {
     if (isNaN(go2to.page.value))
        echo "javascript:alert(&#39;请正确填写转到页数!&#39;);";
       else if (go2to.page.value==""){
        echo "javascript:alert(&#39;请输入转到页数!&#39;);";
      }
     else{
        go2to.submit();
     }
   }

   function getNums(){     //每页最初的记录数
      return $this->nums;
   }
   
   function getOnepage(){      //每页实际条数
      return $this->onepage;
   }

   function getI(){    //暂未用
   //   $this->i=$this-pageone*($this->page-1)
      return $this->i;
   }
   
   function getPage(){
      return $this->page;
   }

   function getMess($error){      //定制消息
      echo"<center>$error</center>";
      exit;
   }
}
?>

<?php
// 测试程序
    $pg=new Pages();
    $pg->getConnect("dsn","user","password");
    $pg->getTotal("select count(*) as total from bul_file");        //连学生表求总数
    $pg->getList($sql,3,$page);
    if($pg->getNums()!=0){
      for($i=0;$i<$pg->getNums();$pg->getfetch_row($pg->dList),$i++);      //同上
    }
    echo "<table width=\"400\" border=1 cellspacing=\"0\" cellpadding=\"0\" bordercolordark=\"#FFFFFF\" bordercolorlight=\"#000000\">";
    echo $pg->getFanye();
    echo "</td></tr></table>";
    echo "<table width=\"400\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolordark=\"#FFFFFF\" bordercolorlight=\"#000000\">";
    echo "<tr bgcolor=\"#CCFF99\"><td width=\"5%\"><font face=\"隶书\" size=\"4\"><div align=\"center\">ID</div></font></td>    <td width=\"50%\"><font face=\"隶书\" size=\"4\"><div align=\"center\">标题</div></font></td>      <td width=\"30%\"><font face=\"隶书\" size=\"4\"><div align=&#39;center&#39;>日期</div></font></td>     </tr>\";
      $i=1;
    while($pg->getfetch_row($pg->dList)){
        $pg->getNums();
        echo "<tr><td width=\"5%\">".($pg->nums+$i)."</a></td><td width=\"50%\"><div align=&#39;center&#39;><a href=\"list_bul.php?id=".$pg->getresult($pg->dList,1)."\" target=\"left\">".$pg->getresult($pg->dList,2)."</a></div></td><td width=\"30%\"><div align=&#39;center&#39;>".substr($pg->getresult($pg->dList,4),1,10)."</div></td></tr>";
        if($i==$pg->getOnepage()){      //跳出循环
           break;
     }
    $i++;
?>

曾因酒醉鞭名马 生怕情多累美人

TOP

支持stmp认证、HTML格式邮件的类

c_smtp_client.php
复制内容到剪贴板
代码:
<?php
/* smtp client class */
class c_smtp_client
{
   var $connection;
   var $server;
   var $elog_fp;
   var $log_file=&#39;./smtp_client.log&#39;;
   var $do_log=true;
   var $need_auth=true;
   var $username;
   var $password;

   // 构造器
   function c_smtp_client($server=&#39;&#39;)
   {
      if (!$server)
      {
        $this->server="localhost";
      }
      else
      {
        $this->server=$server;
      }

      $this->connection = fsockopen($this->server, 25);
      if ($this->connection <= 0) return 0;
      fputs($this->connection,"HELO xyz\r\n");
   }
   
   function email($from_mail, $to_mail, $to_name, $header, $subject, $body)
   {
      if ($this->connection <= 0) return 0;
      
      // 邮件用户认证
      if ($this->need_auth)
      {
        $this->elog("AUTH LOGIN", 1);
        fputs($this->connection,"AUTH LOGIN\r\n");
        $this->elog(fgets($this->connection, 1024));
         
        $base64_username=base64_encode($this->username);
        $this->elog("$base64_username", 1);
        fputs($this->connection,"$base64_username\r\n");
        $this->elog(fgets($this->connection, 1024));

        $base64_password=base64_encode($this->password);
        $this->elog("$base64_password", 1);
        fputs($this->connection,"$base64_password\r\n");
        $this->elog(fgets($this->connection, 1024));
      }

      $this->elog("MAIL FROM:$from_mail", 1);
      fputs($this->connection,"MAIL FROM:$from_mail\r\n");
      $this->elog(fgets($this->connection, 1024));
      
      $this->elog("RCPT TO:$to_mail", 1);
      fputs($this->connection, "RCPT TO:$to_mail\r\n");
      $this->elog(fgets($this->connection, 1024));
      
      $this->elog("DATA", 1);
      fputs($this->connection, "DATA\r\n");
      $this->elog(fgets($this->connection, 1024));

      $this->elog("Subject: $subject", 1);
      $this->elog("To: $to_name", 1);
      fputs($this->connection,"Subject: $subject\r\n");
      fputs($this->connection,"To: $to_name\r\n");

      if ($header)
      {
        $this->elog($header, 1);
        fputs($this->connection, "$header\r\n");
      }

      $this->elog("", 1);
      $this->elog($body, 1);
      $this->elog(".", 1);
      fputs($this->connection,"\r\n");
      fputs($this->connection,"$body \r\n");
      fputs($this->connection,".\r\n");
      $this->elog(fgets($this->connection, 1024));

      return 1;
   }


   function send()
   {
      if ($this->connection)
      {
        fputs($this->connection, "QUIT\r\n");
        fclose($this->connection);
        $this->connection=0;
      }
   }

   function close()
   {
      $this->send();
   }

   function elog($text, $mode=0)
   {
      if (!$this->do_log) return;

      // open file
      if (!$this->elog_fp)
      {
        if (!($this->elog_fp=fopen($this->log_file, &#39;a&#39;))) return;
        fwrite($this->elog_fp, "\n-------------------------------------------\n");
        fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "\n");
        fwrite($this->elog_fp, "-------------------------------------------\n");
      }

      // write to log
      if (!$mode)
      {
        fwrite($this->elog_fp, "   $text\n");
      }
      else
      {
        fwrite($this->elog_fp, "$text\n");
      }
   }
}
?>
c_mail.php
复制内容到剪贴板
代码:
<?php

   /* 邮件发送类 */
   require_once dirname(__FILE__)."/c_smtp_client.php";
   static $c_smtp_client;
   if(!isset($c_smtp_client))
   {
      $c_smtp_client          =   & new c_smtp_client($smtp_server[&#39;name&#39;]);
      $c_smtp_client->do_log    =   false;
      $c_smtp_client->need_auth  =   $smtp_server[&#39;need_auth&#39;];
      $c_smtp_client->username   =   $smtp_server[&#39;username&#39;];
      $c_smtp_client->password   =   $smtp_server[&#39;password&#39;];   
   }

   class c_mail
   {
      // html格式的Mail信笺
      function html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail)
      {
        $headers    =   "";
        $headers   .=   "MIME-Version: 1.0\r\n";
        $headers   .=   "Content-type: text/html; charset=gb2312\r\n";
        $headers   .=   "From: ".$from_name."<".$from_mail.">\r\n";
        $headers   .=   "To: ".$to_name."<".$to_mail.">\r\n";
        $headers   .=   "Reply-To: ".$from_name."<".$reply_mail.">\r\n";
        $headers   .=   "X-Priority: 1\r\n";
        $headers   .=   "X-MSMail-Priority: High\r\n";
        $headers   .=   "X-Mailer: WebCMS MAIL SERV";

        // 开始发送邮件
        if($smtp_server[&#39;name&#39;]==&#39;&#39;)
        {
           @mail($to_mail, $subject, $message, $headers);
        }
        else
        {
           $c_smtp_client->email($from_mail,$to_mail,$to_name,$headers,$subject,$message);
           $c_smtp_client->send();      
        }
      }
}
?>
config.inc.php
复制内容到剪贴板
代码:
<?php
   //smtp_server[&#39;name&#39;]==&#39;&#39;;则表示直接使用mail();      
   //smtp_server[&#39;name&#39;]==&#39;localhost&#39;;表示程序所在主机的smtp服务器
   $smtp_server[&#39;name&#39;]        =   "";
   $smtp_server[&#39;need_auth&#39;]     =   true;
   $smtp_server[&#39;username&#39;]      =   &#39;&#39;;
   $smtp_server[&#39;password&#39;]      =   &#39;&#39;;
?>
sendmail.php
复制内容到剪贴板
代码:
<?php
   //调用方法
   require_once dirname(__FILE__)."/config.inc.php";
   require_once dirname(__FILE__)."/c_mail.php";
   $c_mail   = new c_mail();
   $c_mail->html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail);

?>
曾因酒醉鞭名马 生怕情多累美人

TOP

一个操作xml的类
复制内容到剪贴板
代码:
<?
/*
   (c) 2000 Hans Anderson Corporation.  All Rights Reserved.
   You are free to use and modify this class under the same
   guidelines found in the PHP License.

   -----------

   bugs/me:
   [url]http://www.hansanderson.com/php/[/url]
   [email]me@hansanderson.com[/email]
   [email]showstv@163.com[/email]

   -----------

   Version 1.0

      - 1.0 is the first actual release of the class.  It&#39;s  
       finally what I was hoping it would be, though there
       are likely to still be some bugs in it.  This is
       a much changed version, and if you have downloaded
       a previous version, this WON&#39;T work with your existing
       scripts!  You&#39;ll need to make some SIMPLE changes.

      - .92 fixed bug that didn&#39;t include tag attributes

       (to use attributes, add _attributes[array_index]
        to the end of the tag in question:
        $xml_html_head_body_img would become
        $xml_html_head_body_img_attributes[0],  
        for example)

        -- Thanks to Nick Winfield <[email]nick@wirestation.co.uk[/email]>
          for reporting this bug.

      - .91 No Longer requires PHP4!

      - .91 now all elements are array.  Using objects has
       been discontinued.
*/

class xml_container{

   function store($k,$v) {
      $this->{$k}[] = $v;
   }
}


/* parses the information */
/*********************************
*   类定义开始
*
*********************************/
class xml{
   
   // initialize some variables
   var $current_tag=array();
   var $xml_parser;
   var $Version = 1.0;
   var $tagtracker = array();

   /* Here are the XML functions needed by expat */


   /* when expat hits an opening tag, it fires up this function */
   function startElement($parser, $name, $attrs){

      array_push($this->current_tag, $name); // add tag to the cur. tag array
      $curtag = implode("_",$this->current_tag); // piece together tag

      /* this tracks what array index we are on for this tag */

      if(isset($this->tagtracker["$curtag"])) {
        $this->tagtracker["$curtag"]++;
      }
      else{
        $this->tagtracker["$curtag"]=0;
      }

      /* if there are attributes for this tag, we set them here. */

      if(count($attrs)>0) {
        $j = $this->tagtracker["$curtag"];
        if(!$j) $j = 0;

        if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
           $GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
        }

        $GLOBALS[$this->identifier]["$curtag"][$j]->store("attributes",$attrs);
      }
   
   }// end function startElement



   /* when expat hits a closing tag, it fires up this function */
   function endElement($parser, $name) {
      $curtag = implode("_",$this->current_tag); // piece together tag
      
      // before we pop it off,
      // so we can get the correct
      // cdata

      if(!$this->tagdata["$curtag"]) {
        $popped = array_pop($this->current_tag); // or else we screw up where we are
        return; // if we have no data for the tag
      }
      else{
        $TD = $this->tagdata["$curtag"];
        unset($this->tagdata["$curtag"]);
      }

      $popped = array_pop($this->current_tag);
      // we want the tag name for
      // the tag above this, it  
      // allows us to group the
      // tags together in a more
      // intuitive way.

      if(sizeof($this->current_tag) == 0) return; // if we aren&#39;t in a tag

      $curtag = implode("_",$this->current_tag); // piece together tag
      // this time for the arrays

      $j = $this->tagtracker["$curtag"];
      
      if(!$j) $j = 0;

      if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
        $GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
      }

      $GLOBALS[$this->identifier]["$curtag"][$j]->store($name,$TD);
      #$this->tagdata["$curtag"]);
      unset($TD);
      return TRUE;
   } // end function endElement


   /* when expat finds some internal tag character data,
     it fires up this function */

   function characterData($parser, $cdata) {
      $curtag = implode("_",$this->current_tag); // piece together tag
      $this->tagdata["$curtag"] .= $cdata;
   }


   function xml($data,$identifier=&#39;xml&#39;) {  

      $this->identifier = $identifier;

      // create parser object
      $this->xml_parser = xml_parser_create();

      // set up some options and handlers
      xml_set_object($this->xml_parser,$this);
      xml_parser_set_option($this->xml_parser,XML_OPTION_CASE_FOLDING,0);
      xml_set_element_handler($this->xml_parser, "startElement", "endElement");
      xml_set_character_data_handler($this->xml_parser, "characterData");

      if (!xml_parse($this->xml_parser, $data, TRUE)) {
        sprintf("XML error: %s at line %d",
        xml_error_string(xml_get_error_code($this->xml_parser)),
        xml_get_current_line_number($this->xml_parser));
      }

      // we are done with the parser, so let&#39;s free it
      xml_parser_free($this->xml_parser);

   }//end constructor: function xml()


}//thus, we end our class xml

?>
操作方法:

require(&#39;class.xml.php&#39;);
$file = "data.xml";
$data = implode("",file($file)) or die("could not open XML input file");
$obj = new xml($data,"xml");


print $xml["hans"][0]->num_results[0];
for($i=0;$i<sizeof($xml["hans"]);$i++) {
print $xml["hans"][$i]->tag[0] . " ";
}

To print url attributes (if they exist):

print $xml["hans"][0]->attributes[0]["size"];
曾因酒醉鞭名马 生怕情多累美人

TOP

php输出控制类
复制内容到剪贴板
代码:
<?php
/**
*
*  作者: 徐祖宁 (唠叨)
*  邮箱: [email]czjsz_ah@stats.gov.cn[/email]
*  开发: 2002.07
*
*
*  类: outbuffer
*  功能: 封装部分输出控制函数,控制输出对象。
*
*  方法:
*  run($proc)           运行php程序
*   $proc    php程序名
*  display()            输出运行结果
*  savetofile($filename)    保存运行结果到文件,一般可用于生成静态页面
*   $filename 文件名
*  loadfromfile($filename)  装入保存的文件
*   $filename 文件名
*
*  示例:
*  1.
*  require_once "outbuffer.php";
*  $out = new outbuffer();
*  $out->run("test.php");
*  $out->display();
*
*  2.
*  require_once "outbuffer.php";
*  require_once "outbuffer.php";
*  $out = new outbuffer("test.php");
*  $out->savetofile("temp.htm");
*
*  3.
*  require_once "outbuffer.php";
*  $out = new outbuffer();
*  $out->loadfromfile("temp.htm");
*  $out->display();
*
*/

class outbuffer {
  var $length;
  var $buffer;
  function outbuffer($proc="") {
   $this->run($proc);
  }
  function run($proc="") {
   ob_start();
   include($proc);
   $this->length = ob_get_length();
   $this->buffer = ob_get_contents();
   $this->buffer = eregi_replace("\r?\n","\r\n",$this->buffer);
   ob_end_clean();
  }
  function display() {
   echo $this->buffer;
  }
  function savetofile($filename="") {
   if($filename == "") return;
   $fp = fopen($filename,"w");
   fwrite($fp,$this->buffer);
   fclose($fp);
  }
  function loadfromfile($filename="") {
   if($filename == "") return;
   $fp = fopen($filename,"w");
   $this->buffer = fread($fp,filesize($filename));
   fclose($fp);
  }
}
?>

曾因酒醉鞭名马 生怕情多累美人

TOP

一个分页导航类
复制内容到剪贴板
代码:
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group                      |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,    |
// | that is bundled with this package in the file LICENSE, and is      |
// | available at through the world-wide-web at                  |
// | [url]http://www.php.net/license/2_02.txt.[/url]                      |
// | If you did not receive a copy of the PHP license and are unable to  |
// | obtain it through the world-wide-web, please send a note to       |
// | [email]license@php.net[/email] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// | Authors: Richard Heyes <[email]richard@phpguru.org[/email]>                 |
// +----------------------------------------------------------------------+

/**
* Pager class
*
* Handles paging a set of data. For usage see the example.php provided.
*
*/

class Pager {

   /**
   * Current page
   * @var integer
   */
   var $_currentPage;

   /**
   * Items per page
   * @var integer
   */
   var $_perPage;

   /**
   * Total number of pages
   * @var integer
   */
   var $_totalPages;

   /**
   * Item data. Numerically indexed array...
   * @var array
   */
   var $_itemData;

   /**
   * Total number of items in the data
   * @var integer
   */
   var $_totalItems;

   /**
   * Page data generated by this class
   * @var array
   */
   var $_pageData;

   /**
   * Constructor
   *
   * Sets up the object and calculates the total number of items.
   *
   * @param $params An associative array of parameters This can contain:
   *            currentPage  Current Page number (optional)
   *            perPage     Items per page (optional)
   *            itemData    Data to page
   */
   function pager($params = array())
   {
      global $HTTP_GET_VARS;

      $this->_currentPage = max((int)@$HTTP_GET_VARS[&#39;pageID&#39;], 1);
      $this->_perPage    = 8;
      $this->_itemData   = array();

      foreach ($params as $name => $value) {
        $this->{&#39;_&#39; . $name} = $value;
      }

      $this->_totalItems = count($this->_itemData);
   }

   /**
   * Returns an array of current pages data
   *
   * @param $pageID Desired page ID (optional)
   * @return array Page data
   */
   function getPageData($pageID = null)
   {
      if (isset($pageID)) {
        if (!empty($this->_pageData[$pageID])) {
           return $this->_pa