邪恶八进制信息安全团队技术讨论组's Archiver

天下第七 2006-3-27 03:48

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

<P>信息来源:天下第七收集整理</P>
<P>前面的话:这里收集整理一些php的类,我尽量吧我能看到的都收集过来。希望又对你又用的东西</P>
<P>
<TABLE cellSpacing=0 cellPadding=1 width="85%" align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=3 cellPadding=3 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><FONT size=2>名称: Progress_bar<BR>大小: 1.91 KB<BR>作者:Chris Geisler<BR>来源:PHPClasses</FONT></TD></TR>
<TR>
<TD><FONT size=2></FONT></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><FONT size=2>详细介绍:<BR> 如果你的一段程序需要很长时间才能完成,在这段时间内又不想让你的客户等得不耐烦。那么 Progress_bar 可以帮你做到。<BR><BR>Process_bar 利用java script动态生成一个进度条,并且会根据你的任务进度来实时改变进度条的进度。<BR></FONT></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></P>

天下第七 2006-3-27 03:51

分页类:

[code]<?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;
   }
}
?>
[/code]

天下第七 2006-3-27 03:52

目录操作基类
[code]<?
//目录操作基类
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);
?>
[/code]

天下第七 2006-3-27 03:53

日历类
[code]<?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();
?>
[/code]

天下第七 2006-3-27 03:55

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

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

天下第七 2006-3-27 03:57

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

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


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

天下第七 2006-3-27 03:58

购物车的类,只用了一个Session

[code]<?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  
}

?>


[/code]

天下第七 2006-3-27 03:59

odbc连mssql分页的类
[code]<?
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++;
?>


[/code]

天下第七 2006-3-27 04:02

[b]支持stmp认证、HTML格式邮件的类[/b]

c_smtp_client.php
[code]
<?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");
      }
   }
}
?>


[/code]
c_mail.php
[code]
<?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();      
        }
      }
}
?>

[/code]
config.inc.php
[code]<?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;;
?>

[/code]
sendmail.php

[code]<?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);

?>
[/code]

天下第七 2006-3-27 04:03

[b]一个操作xml的类[/b]
[code]<?
/*
   (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

?>


[/code]

操作方法:

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"];

天下第七 2006-3-27 04:04

php输出控制类
[code]<?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);
  }
}
?>


[/code]

天下第七 2006-3-27 04:05

一个分页导航类
[code]<?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->_pageData[$pageID];
        } else {
           return FALSE;
        }
      }

      if (!isset($this->_pageData)) {
        $this->_generatePageData();
      }

      return $this->getPageData($this->_currentPage);
   }

   /**
   * Returns pageID for given offset
   *
   * @param $index Offset to get pageID for
   * @return int PageID for given offset
   */
   function getPageIdByOffset($index)
   {
      if (!isset($this->_pageData)) {
        $this->_generatePageData();
      }

      if (($index % $this->_perPage) > 0) {
        $pageID = ceil((float)$index / (float)$this->_perPage);
      } else {
        $pageID = $index / $this->_perPage;
      }

      return $pageID;
   }

   /**
   * Returns offsets for given pageID. Eg, if you
   * pass it pageID one and your perPage limit is 10
   * it will return you 1 and 10. PageID of 2 would
   * give you 11 and 20.
   *
   * @params pageID PageID to get offsets for
   * @return array  First and last offsets
   */
   function getOffsetByPageId($pageid = null)
   {
      $pageid = isset($pageid) ? $pageid : $this->_currentPage;
      if (!isset($this->_pageData)) {
        $this->_generatePageData();
      }

      if (isset($this->_pageData[$pageid])) {
        return array(($this->_perPage * ($pageid - 1)) + 1, min($this->_totalItems, $this->_perPage * $pageid));
      } else {
        return array(0,0);
      }
   }

   /**
   * Returns back/next and page links
   *
   * @param  $back_html HTML to put inside the back link
   * @param  $next_html HTML to put inside the next link
   * @return array Back/pages/next links
   */
   function getLinks($back_html = &#39;<< Back&#39;, $next_html = &#39;Next >>&#39;)
   {
      $url  = $this->_getLinksUrl();
      $back  = $this->_getBackLink($url, $back_html);
      $pages = $this->_getPageLinks($url);
      $next  = $this->_getNextLink($url, $next_html);

      return array($back, $pages, $next, &#39;back&#39; => $back, &#39;pages&#39; => $pages, &#39;next&#39; => $next);
   }

   /**
   * Returns number of pages
   *
   * @return int Number of pages
   */
   function numPages()
   {
      return $this->_totalPages;
   }

   /**
   * Returns whether current page is first page
   *
   * @return bool First page or not
   */
   function isFirstPage()
   {
      return ($this->_currentPage == 1);
   }

   /**
   * Returns whether current page is last page
   *
   * @return bool Last page or not
   */
   function isLastPage()
   {
      return ($this->_currentPage == $this->_totalPages);
   }

   /**
   * Returns whether last page is complete
   *
   * @return bool Last age complete or not
   */
   function isLastPageComplete()
   {
      return !($this->_totalItems % $this->_perPage);
   }

   /**
   * Calculates all page data
   */
   function _generatePageData()
   {
      $this->_totalItems = count($this->_itemData);
      $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
      $i = 1;
      if (!empty($this->_itemData)) {
        foreach ($this->_itemData as $value) {
           $this->_pageData[$i][] = $value;
           if (count($this->_pageData[$i]) >= $this->_perPage) {
              $i++;
           }
        }
      } else {
        $this->_pageData = array();
      }
   }

   /**
   * Returns the correct link for the back/pages/next links
   *
   * @return string Url
   */
   function _getLinksUrl()
   {
      global $HTTP_SERVER_VARS;

      // Sort out query string to prevent messy urls
      $querystring = array();
      if (!empty($HTTP_SERVER_VARS[&#39;QUERY_STRING&#39;])) {
        $qs = explode(&#39;&&#39;, $HTTP_SERVER_VARS[&#39;QUERY_STRING&#39;]);        
        for ($i = 0, $cnt = count($qs); $i < $cnt; $i++) {
           list($name, $value) = explode(&#39;=&#39;, $qs[$i]);
           if ($name != &#39;pageID&#39;) {
              $qs[$name] = $value;
           }
           unset($qs[$i]);
        }
      }
   if(is_array($qs)){
        foreach ($qs as $name => $value) {
           $querystring[] = $name . &#39;=&#39; . $value;
        }   
   }
      return $HTTP_SERVER_VARS[&#39;SCRIPT_NAME&#39;] . &#39;?&#39; . implode(&#39;&&#39;, $querystring) . (!empty($querystring) ? &#39;&&#39; : &#39;&#39;) . &#39;pageID=&#39;;
   }

   /**
   * Returns back link
   *
   * @param $url  URL to use in the link
   * @param 上一篇    目录    下一篇 HTML to use as the link
   * @return string The link
   */
   function _getBackLink($url, 上一篇    目录    下一篇 = &#39;<< Back&#39;)
   {
      // Back link
      if ($this->_currentPage > 1) {
        $back = &#39;<a href="&#39; . $url . ($this->_currentPage - 1) . &#39;">&#39; . 上一篇    目录    下一篇 . &#39;</a>&#39;;
      } else {
        $back = &#39;&#39;;
      }
      
      return $back;
   }

   /**
   * Returns pages link
   *
   * @param $url  URL to use in the link
   * @return string Links
   */
   function _getPageLinks($url)
   {
      // Create the range
      $params[&#39;itemData&#39;] = range(1, max(1, $this->_totalPages));
      $pager =& new Pager($params);
      上一篇    目录    下一篇s =  $pager->getPageData($pager->getPageIdByOffset($this->_currentPage));

      for ($i=0; $i<count(上一篇    目录    下一篇s); $i++) {
        if (上一篇    目录    下一篇s[$i] != $this->_currentPage) {
           上一篇    目录    下一篇s[$i] = &#39;<a href="&#39; . $this->_getLinksUrl() . 上一篇    目录    下一篇s[$i] . &#39;">&#39; . 上一篇    目录    下一篇s[$i] . &#39;</a>&#39;;
        }
      }

      return implode(&#39; &#39;, 上一篇    目录    下一篇s);
   }

   /**
   * Returns next link
   *
   * @param $url  URL to use in the link
   * @param 上一篇    目录    下一篇 HTML to use as the link
   * @return string The link
   */
   function _getNextLink($url, 上一篇    目录    下一篇 = &#39;Next >>&#39;)
   {
      if ($this->_currentPage < $this->_totalPages) {
        $next = &#39;<a href="&#39; . $url . ($this->_currentPage + 1) . &#39;">&#39; . 上一篇    目录    下一篇 . &#39;</a>&#39;;
      } else {
        $next = &#39;&#39;;
      }

      return $next;
   }
}

?>


[/code]

天下第七 2006-3-27 04:07

两个日期类
[code]<?
/**
  这是公历和农历类的定义,由于php的日期计算限制,所以只能计算1970-1938之间的时间
  农历类的计算方法使用了林洵贤先生的算法,在此表示感谢!在joy Asp可以找到林先生的大作(javascript)
*/

/**
* 日期类
* 本对象套用JavaScript的日期对象的方法
* 设置$mode属性,可兼容JavaScript日期对象
*/
class Date {
  var $time = 0;
  var $mode = 0;  // 本属性为与JavaScript兼容而设,$mode=1为JavaScript方式
  var $datemode = "Y-m-d H:i:s";  // 日期格式 "Y-m-d H:i:s",可自行设定
  function Date($t=0) {
   if($t == 0)
    $this->time = time();
  }
  /**
  * 返回从GMT时间1970年1月1日0时开始的毫秒数
  */
  function getTime() {
   $temp = gettimeofday();
   return $temp[sec]*1000+round($temp[usec]/1000);
  }
  /**
  * 返回年份
  */
  function getYear() {
   $temp = getdate($this->time);
   return $temp[year];
  }
  /**
  * 返回月份
  */
  function getMonth() {
   $temp = getdate($this->time);
   return $temp[mon]-$this->mode;
  }
  /**
  * 返回日期
  */
  function getDate() {
   $temp = getdate($this->time);
   return $temp[mday];
  }
  /**
  * 返回星期
  */
  function getDay() {
   $temp = getdate($this->time);
   return $temp[wday]-$this->mode;
  }
  /**
  * 返回小时
  */
  function getHours() {
   $temp = getdate($this->time);
   return $temp[hours];
  }
  /**
  * 返回分
  */
  function getMinutes() {
   $temp = getdate($this->time);
   return $temp[minutes];
  }
  /**
  * 返回秒
  */
  function getSeconds() {
   $temp = getdate($this->time);
   return $temp[seconds];
  }
  /**
  * 设定年份
  * php 4.0.6 year 1970 -- 2038
  */
  function setYear($val) {
   $temp = getdate($this->time);
   $temp[year] = $val;
   $this->set_time($temp);
  }
  /**
  * 设定月份
  */
  function setMonth($val) {
   $temp = getdate($this->time);
   $temp[mon] = $val+$this->mode;
   $this->set_time($temp);
  }
  /**
  * 设定日期
  */
  function setDate($val) {
   $temp = getdate($this->time);
   $temp[mday] = $val;
   $this->set_time($temp);
  }
  /**
  * 设定星期
  */
  function setDay($val) {
   $temp = getdate($this->time);
   $temp[wday] = $val+$this->mode;
   $this->set_time($temp);
  }
  /**
  * 设定小时
  */
  function setHours($val) {
   $temp = getdate($this->time);
   $temp[hours] = $val;
   $this->set_time($temp);
  }
  /**
  * 设定分
  */
  function setMinutes($val) {
   $temp = getdate($this->time);
   $temp[minutes] = $val;
   $this->set_time($temp);
  }
  /**
  * 设定秒
  */
  function setSeconds($val) {
   $temp = getdate($this->time);
   $temp[seconds] = $val;
   $this->set_time($temp);
  }
  /**
  * 返回系统格式的字符串
  */
  function toLocaleString() {
   return date($this->datemode,$this->time);
  }
  /**
  * 使用GTM时间创建一个日期值
  */
  function UTC($year,$mon,$mday,$hours=0,$minutes=0,$seconds=0) {
   $this->time = mktime($hours,$minutes,$seconds,$mon,$mday,$year);
   return $this->time;
  }
  /**
  * 等价于DateAdd(interval,number,date)
  * 返回已添加指定时间间隔的日期。
  * Inetrval为表示要添加的时间间隔字符串表达式,例如分或天
  * number为表示要添加的时间间隔的个数的数值表达式
  * Date表示日期
  *
  * Interval(时间间隔字符串表达式)可以是以下任意值:
  *  yyyy year年
  *  q Quarter季度
  *  m Month月
  *  y Day of year一年的数
  *  d Day天
  *  w Weekday一周的天数
  *  ww Week of year周
  *  h Hour小时
  *  n Minute分
  *  s Second秒
  *  w、y和d的作用是完全一样的,即在目前的日期上加一天,q加3个月,ww加7天。
  */
  function Add($interval, $number, $date) {
   $date = Date::get_time($date);
   $date_time_array = getdate($date);
   $hours = $date_time_array["hours"];
   $minutes = $date_time_array["minutes"];
   $seconds = $date_time_array["seconds"];
   $month = $date_time_array["mon"];
   $day = $date_time_array["mday"];
   $year = $date_time_array["year"];
   switch ($interval) {
    case "yyyy": $year +=$number; break;
    case "q": $month +=($number*3); break;
    case "m": $month +=$number; break;
    case "y":
    case "d":
    case "w": $day+=$number; break;
    case "ww": $day+=($number*7); break;
    case "h": $hours+=$number; break;
    case "n": $minutes+=$number; break;
    case "s": $seconds+=$number; break;
   }
   $temptime = mktime($hours ,$minutes, $seconds,$month ,$day, $year);
   return $temptime;
  }
  /**
  * 等价于DateDiff(interval,date1,date2)
  * 返回两个日期之间的时间间隔
  * intervals(时间间隔字符串表达式)可以是以下任意值:
  *  w  周
  *  d  天
  *  h  小时
  *  n  分钟
  *  s  秒
  */
  function Diff($interval, $date1,$date2) {
   // 得到两日期之间间隔的秒数
   $timedifference = Date::get_time($date2) - Date::get_time($date1);
   switch ($interval) {
    case "w": $retval = bcdiv($timedifference ,604800); break;
    case "d": $retval = bcdiv( $timedifference,86400); break;
    case "h": $retval = bcdiv ($timedifference,3600); break;
    case "n": $retval = bcdiv( $timedifference,60); break;
    case "s": $retval = $timedifference; break;
   }
   return $retval;
  }

  /**
  * 输出,根据需要直接修改本函数或在派生类中重写本函数
  */
  function display() {
   $nStr = array(&#39;日&#39;,&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;);
   echo sprintf("%4d年%2d月%2d日 星期%s<br>",$this->getYear(),$this->getMonth(),$this->getDate(),$nStr[$this->getDay()%7]);
  }
  /**
  * 工作函数
  */
  function set_time(&$ar) {
   $this->time = mktime($ar[hours],$ar[minutes],$ar[seconds],$ar[mon],$ar[mday],$ar[year]);
  }
  /**
  * 转换为UNIX时间戳
  */
  function get_time($d) {
   if(is_numeric($d))
    return $d;
   else {
    if(! is_string($d)) return 0;
    if(ereg(":",$d)) {
      $buf = split(" +",$d);
      $year = split("[-/]",$buf[0]);
      $hour = split(":",$buf[1]);
      if(eregi("pm",$buf[2]))
       $hour[0] += 12;
      return mktime($hour[0],$hour[1],$hour[2],$year[1],$year[2],$year[0]);
    }else {
      $year = split("[-/]",$d);
      return mktime(0,0,0,$year[1],$year[2],$year[0]);
    }
   }
  }
} // 日期类定义结束
?>

<?
/**
* 农历类
*/
class Lunar {
  var $year;
  var $month;
  var $day;
  var $isLeap;
  var $yearCyl;
  var $dayCyl;
  var $monCyl;
  var $time;
  var $lunarInfo = array(
   0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
   0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
   0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
   0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
   0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
   0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
   0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
   0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
   0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
   0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
   0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
   0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
   0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
   0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
   0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0,
   0x14b63);

  /**
  * 传回农历 y年的总天数
  */
  function lYearDays($y) {
   $sum = 348;
   for($i=0x8000; $i>0x8; $i>>=1)
    $sum += ($this->lunarInfo[$y-1900] & $i)? 1: 0;
   return $sum+$this->leapDays($y);
  }
  /**
  * 传回农历 y年闰月的天数
  */
  function leapDays($y) {
   if($this->leapMonth($y))
    return ($this->lunarInfo[$y-1900] & 0x10000)? 30: 29;
   else return 0;
  }
  /**
  * 传回农历 y年闰哪个月 1-12 , 没闰传回 0
  */
  function leapMonth($y) {
   return $this->lunarInfo[$y-1900] & 0xf;
  }
  /**
  * 传回农历 y年m月的总天数
  */
  function monthDays($y,$m) {
   return ($this->lunarInfo[$y-1900] & (0x10000>>$m))? 30: 29;
  }
  /**
  * 创建农历日期对象
  */
  function Lunar($objDate,$month=1,$day=1) {
   $leap=0;
   $temp=0;
   if(is_object($objDate))
    $this->time = mktime(0,0,0,$objDate->getMonth(),$objDate->getDate(),$objDate->getYear());
   else {
    $year = $objDate;
    $this->time = mktime(0,0,0,$month,$day,$year);
    if($year < 1970) {
      return;
      $temp = 0;
      for($i=1970; $i>$year; $i--) {
       $temp = $this->lYearDays($i);
       $offset -= $temp;
      }
    }
   }
   $offset = round($this->time/86400+25537);

   $this->dayCyl = $offset + 40;
   $this->monCyl = 14;

   for($i=1900; $i<$year && $offset>0; $i++) {
    $temp = $this->lYearDays($i);
    $offset -= $temp;
    $this->monCyl += 12;
   }

   if($offset<0) {
    $offset += $temp;
    $i--;
    $this->monCyl -= 12;
   }

   $this->year = $i;
   $this->yearCyl = $i-1864;
   $leap = $this->leapMonth($i); //闰哪个月

   $this->isLeap = false;
   for($i=1; $i<13 && $offset>0; $i++) {
    //闰月
    if($leap>0 && $i==($leap+1) && $this->isLeap==false) {
      $i--;
      $this->isLeap = true;
      $temp = $this->leapDays($this->year);
    }else {
      $temp = $this->monthDays($this->year, $i);
    }

    //解除闰月
    if($this->isLeap==true && $i==($leap+1))
      $this->isLeap = false;

    $offset -= $temp;
    if($this->isLeap == false)
      $this->monCyl ++;
   }

   if($offset==0 && $leap>0 && $i==$leap+1)
    if($this->isLeap)
      $this->isLeap = false;
    else {
      $this->isLeap = true;
      $i--;
      $this->monCyl--;
    }

   if($offset<0) {
    $offset += $temp;
    $i--;
    $this->monCyl--;
   }

   $this->month = $i;
   $this->day = $offset + 1;
  }

  function cyclical($num) {
   $Gan = Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
   $Zhi = Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
   return $Gan[$num%10].$Zhi[$num%12];
  }
  /**
  * 输出,根据需要直接修改本函数或在派生类中重写本函数
  */
  function display() {
   $nStr = array(&#39; &#39;,&#39;正&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;,&#39;七&#39;,&#39;八&#39;,&#39;九&#39;,&#39;十&#39;,&#39;十一&#39;,&#39;腊&#39;);
   echo sprintf("农历 %s%s月%s<br>",($this->isLeap?"闰":""),$nStr[$this->month],$this->cDay($this->day));
   echo sprintf("%s年 %s月 %s日",$this->cyclical($this->yearCyl),$this->cyclical($this->monCyl),$this->cyclical($this->dayCyl));
  }
  /**
  * 中文日期
  */
  function cDay($d) {
   $nStr1 = array(&#39;日&#39;,&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;,&#39;七&#39;,&#39;八&#39;,&#39;九&#39;,&#39;十&#39;);
   $nStr2 = array(&#39;初&#39;,&#39;十&#39;,&#39;廿&#39;,&#39;卅&#39;,&#39; &#39;);

   switch($d) {
    case 10:
      $s = &#39;初十&#39;;
      break;
    case 20:
      $s = &#39;二十&#39;;
      break;
    case 30:
      $s = &#39;三十&#39;;
      break;
    default :
      $s = $nStr2[floor($d/10)];
      $s .= $nStr1[$d%10];
   }
   return $s;
  }
}  // 农历类定义结束
?>

<?
//  测试例


$d = new Date;
echo "<br>现在是:";
$d->display();

$d->setYear(2037);
echo "<br>现在是:";
echo $d->getYear()."年";
echo $d->getMonth()."月";
echo $d->getDate()."日";
echo " 星期".$d->getDay()." ";
echo $d->getHours()."时";
echo $d->getMinutes()."分";
echo $d->getSeconds()."秒<br>";

$d->UTC(1998,10,2,22,0,8);
echo $d->toLocaleString()."<br>";

$d = new Date;
$ld = new Lunar($d);
$d->display();
$ld->display();
$d->UTC(1998,10,2,22,0,8);
$ld = new Lunar($d);
$d->display();
$ld->display();
$ld = new Lunar(2002,2,12);
$ld->display();

echo __LINE__."<BR>";

$d1 = "2002-01-11";
$d2 = date("Y-m-d",$d->add("d",35,$d1));

echo $d1."的". Date::diff("d",$d1,$d2)."天后是$d2<br>";
echo $d1."的10天前是".date("Y-m-d",Date::add("d",-10,$d1))."<br>";
$d3 = date("Y/m/d H:i:s");
echo "现在是".$d3."距离2002/2/12 12:59:59还有".Date::diff("s",$d3,"2002/2/12 12:59:59")."秒<br>";
?>


[/code]

天下第七 2006-3-27 04:08

一个访问ACCESS的类
[code]<?
Class AccessDBM
{
   var $COUNT = 0;
   var $VALUES = array();
   var $FILE = "";
   var $ERROR = "";
   var $EXISTS = false;
   var $STATIC = false;
   var $EXACT = false;
   var $DBM;

//   Older version of PHP can&#39;t do the &#39;new ClassName(args)&#39;
//   Use initilize() if this is the case.

//   *******************************************************

   function AccessDBM ($dbmFile, $static = 0)
   {
      global $php_errormsg;

      if(!empty($dbmFile))
      {
        if(file_exists($dbmFile))
        {
           $this->EXISTS = true;
        }
        if($static != 0)
        {
           $this->STATIC = true;
        }
        $this->FILE = $dbmFile;
      }
      return;
   }

//   *******************************************************

//   Identical to AccessDBM
   function initialize ($dbmFile, $static = 0)
   {
      global $php_errormsg;

      if(!empty($dbmFile))
      {
        if(file_exists($dbmFile))
        {
           $this->EXISTS = true;
        }
        if($static != 0)
        {
           $this->STATIC = true;
        }
        $this->FILE = $dbmFile;
      }
      return;
   }

//   *******************************************************

   function add_entry ($key, $val)
   {
      $results = 0;
      $dbm = $this->open_dbm();
      if(!$dbm) { return false; }

      if(!(dbmreplace($dbm,$key,$val)))
      {
        if(!(dbmexists($dbm,$key)))
        {
           $this->ERROR = "Fatal error : could not replace $key with $val";
           $this->close_dbm($dbm);
           return false;
        }
      }
      $this->close_dbm($dbm);
      return true;      
   }

//   *******************************************************

   function remove_entry ($Key)
   {
      global $php_errormsg;
      $removed = false;

      $dbm = $this->open_dbm();
      if(!$dbm) { return false; }

      if(dbmexists($dbm,$Key))
      {
        if(!dbmdelete($dbm,$Key))
        {
           if(dbmexists($dbm,$Key))
           {
              $this->ERROR = "Unable to remove [$Key] : [$php_errormsg]";
              $this->close_dbm($dbm);
              return false;
           }
        }
        else
        {
           $this->close_dbm($dbm);
           $removed = true;
        }
      }
      else
      {
        $this->ERROR = "Key [$Key] does not exist";
        $this->close_dbm($dbm);
        return false;
      }
      return true;
   }

//   *******************************************************

   function get_value ($Key)
   {
      $val = "";
      $readOnly = true;

      $dbm = $this->open_dbm($readOnly);

      if(!$dbm) { return false; }

      if(dbmexists($dbm,$Key))
      {
        $val = dbmfetch($dbm,$Key);
      }
      $this->close_dbm($dbm);
      return $val;
   }

//   *******************************************************

   function open_dbm ($readOnly = false)
   {
      global $php_errormsg;

      if($this->STATIC)
      {
        if(!(empty($this->DBM)))
        {
           $dbm = $this->DBM;
           return ($dbm);
        }
      }

      $fileName = $this->FILE;

      if(!$this->EXISTS)
      {
        $dbm = @dbmopen($fileName,"n");
      }
      else
      {
        if(!$readOnly)
        {
           // We want the warning here if we can&#39;t be
           // a writer
           $dbm = dbmopen($fileName,"w");
        }
        else
        {
           $dbm = @dbmopen($fileName,"r");
        }
      }
      if( (!$dbm) or (empty($dbm)) )
      {
        $this->EXISTS = false;
        $this->STATIC = false;
        $this->ERROR = "Unable to open [$fileName] [$php_errormsg]";
        return false;
      }
      $this->EXISTS = true;
      if($this->STATIC)
      {
        $this->DBM = $dbm;
      }

      return ($dbm);

   }

//   *******************************************************

   function find_key ($search)
   {
      $val = "";

      $dbm = $this->open_dbm(1);
      if(!$dbm) { return false; }
      if(dbmexists($dbm,$search))
      {
        // Wow an exact match
        $val = dbmfetch($dbm,$search);
        $this->close_dbm($dbm);
        $this->EXACT = true;
        return $val;
      }
      else
      {
        $this->EXACT = false;
        $key = dbmfirstkey($dbm);
        while ($key)
        {
           // Strip the first whitespace char and
           // everything after it.
           $test = ereg_replace(" .*","",$key);
           if(eregi("^$test",$search))
           {
              $val = dbmfetch($dbm,$key);
              $this->close_dbm($dbm);
              error_log("Test [$test] matched [$search]",0);
              return $val;
           }
           $key = dbmnextkey($dbm,$key);
        }
      }
      // Didn&#39;t find it
      $this->close_dbm($dbm);
      return false;
   }

//   *******************************************************

   // Returns the KEY
   function find_val ($search)
   {
      $this->EXACT = false;

      $Dbase = $this->get_all();
      if(empty($Dbase))
      {
        error_log("ERROR Dbase is empty $DB->ERROR",0);
        return false;
      }
      while ( list ( $key, $val ) = each ($Dbase) )
      {
        if($search == $val)
        {
           $this->EXACT=true;
           return $key;
        }
        else
        {
           // Strip the first whitespace char and
           // everything after it.

           $test = ereg_replace(" .*","",$val);

           if(eregi("^$test",$search))
           {
              $this->EXACT = false;
              return $key;
           }
        }
      }
      // Didn&#39;t find it
      return false;
   }

//   *******************************************************

   function get_all ()
   {
      $values = array();
      $count = 0;
      $readOnly = true;
      $dbm = $this->open_dbm($readOnly);
      if(!$dbm) { return false; }

      $key = dbmfirstkey($dbm);

      while ($key)
      {
        $val = dbmfetch($dbm,$key);
        $values[$key] = $val;
        $count++;
        $key = dbmnextkey($dbm, $key);
      }
      $this->COUNT = $count;
      $this->VALUES = $values;
      $this->close_dbm($dbm);
      return $values;
   }

//   *******************************************************

   function close_dbm ($dbm)
   {
      $results = false;

      if(!$this->STATIC)
      {
        $results = dbmclose($dbm);
      }
      return $results;
   }


//   *******************************************************

   function static_close()
   {
      $results = false;

      if(!$this->DBM)
      {
        $this->ERROR = "No static DBM to close";
        return false;
      }
      $dbm = $this->DBM;
      $results = dbmclose($dbm);
      unset($this->DBM);
      return $results;
   }

//   *******************************************************

}
?>

[/code]

这个连接上!
include("class.AccessDBM.php3");
   $static = true;
   $dbase = new AccessDBM("/path/to/file.dbm",$static);


   register_shutdown_function($dbase->static_close());


   if(!$dbase->add_entry("cdi","[email]cdi@thewebmasters.net[/email]))
   {
      echo "Error adding entry: $dbase->ERROR\n";
   }
   $Values = $dbase->get_all()
   while ( list ($key,$val) = each ($Values) )
   {
      echo "Key: $key  Val: $val \n";
   }
   exit;

天下第七 2006-3-27 04:09

用PHP写的SMTP类,支持附件(多个),支持HTML
[code]
<?
/***********************************
PHP MIME SMTP ver 1.0 Powered by Boss_ch, Unigenius soft ware co. Ltd
All rights reserved, Copyright 2000 ;
本类用 PHP 通过 smtp  sock 操作发送 MIME 类型的邮件,可以发送
HTML 格式的正文、附件,采用 base64 编码
本版本是针对个人的发送,与多人群发版本不同的是,每发送到一个人,就重新进行一次编码,在接收端的用户看来,只是发送给他一个人的。
针对多人群发的情况,只发送一次,通过多个 RCPT TO 命令⑺偷讲煌娜诵畔渲校?
说明:
请把 $hostname 设为你有权限的 默认 smtp 服务器或是在 new 时指定
把 $charset 改成你的默认 字符集
Html 正文中如有图片,请用绝对路径的引用 "[url]httP://host/path/image.gif[/url]";
  并连上网,以保证程序能读取到图片的数据信息
如果是通过表单提交过来的 Html 正文,请先用 StripSlashes($html_body) 把正文内容进行预处理
  Html 中用到的样式表文件,请不要用 <link >之类 的引用,直接把样式表定义放在
<style></style>标签中

转载请保留此版权信息, Bugs Report : [email]boss_ch@china.com[/email]
*************************************/
if(!isset($__smtp_class__)){
$__smtp_class__=1;

class smtp
{
var $hostname="";
var $port=25;