用PHP如何操作LDAP

1 LDAP是什么
LDAP是一个用来发布目录信息到许多不同资源的协议。通常它都作为一个集中的地址本使用,不过根据组织者的需要,它可以做得更加强大。
  LDAP最基本的形式是一个连接数据库的标准方式。该数据库为读查询作了优化。因此它可以很快地得到查询结果,不过在其它方面,例如更新,就慢得多。要非凡注重的是,LDAP通常作为一个hierarchal数据库使用,而不是一个关系数据库。因此,它的结构用树来表示比用表格好。正因为这样,就不能用SQL语句了。

  简单说来,LDAP是一个得到关于人或者资源的集中、静态数据的快速方式。

LDAP是轻量目录访问协议(Lightweight Directory Access Protocol)的缩写,其实是一话号码簿,类似于我们所使用诸如NIS(Network Information Service)、DNS (Domain Name Service)等网络目录,也类似于你在花园中所看到的树木。
LDAP是一种非凡的数据库。但是LDAP和一般的数据库不同,明白这一点是很重要的。 LDAP对查询进行了优化,与写性能相比LDAP的读性能要优秀很多。
1.1 LDAP的存储规则
区分名(DN,Distinguished Name)
和自然界中的树不同,文件系统/LDAP/电话号码簿目录的每一片枝叶都至少有一个独一无二的属性,这一属性可以帮助我们来区别这些枝叶。
在文件系统中, 这些独一无二的属性就是带有完整路径的文件名。比如/etc/passwd,该文件名在该路径下是独一无二的。当然我们可以有/usr/passwd, /opt/passwd,但是根据它们的完整路径,它们仍然是唯一的。
在LDAP中,一个条目的区分名称叫做“dn”或者叫做区分名。在一个目录中这个名称总是唯一的。比如,我的dn是"uid=aghaffar, ou=People, o=developer.ch"。不可能有相同的dn,但是我们可以有诸如"uid=aghaffar, ou=Administrators, o=developer.ch"的dn。这同上面文件系统中/etc/passwd 和 /usr/passwd的例子很类似。
我们有独一无二的属性,在"ou=Administrators, o=developer.ch" 中uid和在"ou=People, o=developer.ch"中的uid。这并不矛盾。
CN=Common Name 为用户名或服务器名,最长可以到80个字符,可以为中文;
OU=Organization Unit为组织单元,最多可以有四级,每级最长32个字符,可以为中文;
O=Organization 为组织名,可以3

阅读全文

自己动手做一个SQL解释器

这是从别的地方看到的,俺还不会写这么无聊的东西

<?php

class DB_text {
var $conn;
var $classname = "db_text";
var $database;
function on_create() {
}
function connect($database_name) {
$this->database = $database_name;
if(! file_exists($database_name)) {
$this->conn = array();
$this->_close();
}
$fp = fopen($this->database,"r");
$this->conn = unserialize(fread($fp,filesize($this->database)));
fclose($fp);
}
function &query($query) {
if(eregi("select ",$query)) return $this->_select($query);
if(eregi("insert ",$query)) return $this->_insert($query);
if(eregi("delete ",$query)) return $this->_delete($query);
if(eregi("update ",$query)) return $this->_update($query);
return array();
}
function fetch_row(&$result) {
if(list($key,$value) = each($result))
return $value;
return false;
}
function num_rows($result) {
return count($result);
}

/**
* query的辅助函数
*/
function _select($query) {
if(eregi("(order by (. ))",$query,$regs)) {
$order = $regs[2];
$query = eregi_replace($regs[1],"",$query);
}
if(eregi("(group by (. ))",$query,$regs)) {
$group = $regs[2];
$query = eregi_replace($regs[1],"",$query);
}
eregi("select .* from ([0-9a-z_] ) *(where (. ))?",$query,$regs);
if($regs[3] != "") {
$keys = $this->_where($regs[3],"$this->conn[$regs[1]]");
while(list($key,$value) = each($keys)) {
$rs[] = $this->conn[$regs[1]][$value];
}
}else {
$rs = $this->conn[$regs[1]];
}
if($order) {
sscanf($order,"%s %s",$key,$type);
if(empty($type)) $type = "asc";
$this->_sort($rs,$key,$type);
}
return $rs;

阅读全文

下拉透明菜单三

function mwritetodocument(){
      var mwb=1;
                     var stringx='<div id="mposflag" style="position:absolute;"></div><table  id=mmenutable border=0 cellpadding=3 cellspacing=2 width='+mmenuwidth+' height='+mmenuheight+' bgcolor='+mmenucolor+
                     ' onselectstart="event.returnValue=false"'+
                     ' style="filter:Alpha(Opacity=80);cursor:'+mcursor+';'+mfonts+
                     ' border-left: '+mwb+'px solid '+mmenuoutbordercolor+';'+
                     ' border-right: '+mwb+'px solid '+mmenuinbordercolor+'; '+
                     'border-top: '+mwb+'px solid '+mmenuoutbordercolor+'; '+
                     'border-bottom: '+mwb+'px solid '+mmenuinbordercolor+'; padding:0px"><tr>'
                     for(var x=0;x<mmenus.length;x++){
                      var thismenu=mmenus[x];
                      var imgsize="";
                      if(thismenu.sizex!="0"||thismenu.sizey!="0")imgsize=" width="+thismenu.sizex+" height="+thismenu.sizey;
                      var ifspace="";
                      if(thismenu.caption!="")ifspace=" ";
                      stringx += "<td nowrap class=coolButton id=mMenu"+x+" style='border: "+mitemedge+"px solid "+mmenucolor+
                      "' width="+mmenuunitwidth+"px onmouseover=mmenu_over(mmenudiv"+x+
                      ","+x+") onmouseout=mmenu_out("+x+
                      ") onmousedown=mmenu_down(mmenudiv"+x+","+x+")";
                            if(thismenu.command!=""){
                                stringx += " onmouseup=mmenu_up();mexec2("+x+");";
                            }else{
                               stringx += " onmouseup=mmenu_up()";
                            }
                            if(thismenu.pos=="0"){
                                stringx += " align=center><img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenu.jpg'"+imgsize+">"+ifspace+thismenu.caption+"</td>";
                            }else if(thismenu.pos=="1"){
                                stringx += " align=center>"+thismenu.caption+ifspace+"<img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenu.jpg'"+imgsize+"></td>";
                            }else if(thismenu.pos=="2"){
                                stringx += " align=center background='http://pic3.phprm.com/2015/07/04/"+thismenu.jpg'> "+thismenu.caption+" </td>";
                            }else{
                                stringx += " align=center> "+thismenu.caption+" </td>";
                            }
                      stringx += "";
                     }
                     stringx+="<td width=*> </td></tr></table>";
                    
                    
                     for(var x=0;x<mmenus.length;x++){
                      thismenu=mmenus[x];
                        if(x<0){
                        stringx+='<div id=mmenudiv'+x+' style="visiable:none"></div>';
                        }else{
                        stringx+='<div id=mmenudiv'+x+
                        ' style="filter:Alpha(Opacity=80);cursor:'+mcursor+';position:absolute;'+
                        'width:'+mmenuitemwidth+'px; z-index:'+(x+100);
                        if(mmenuinbordercolor!=mmenuoutbordercolor&&msubedge=="0"){
                        stringx+=';border-left: 1px solid '+mmidoutcolor+
                        ';border-top: 1px solid '+mmidoutcolor;}
                        stringx+=';border-right: 1px solid '+mmenuinbordercolor+
                        ';border-bottom: 1px solid '+mmenuinbordercolor+';visibility:hidden" onselectstart="event.returnValue=false">n'+
                      '<table  width="100%" border="0" height="100%" align="center" cellpadding="0" cellspacing="2" '+
                      'style="'+mfonts+' border-left: 1px solid '+mmenuoutbordercolor;
                      if(mmenuinbordercolor!=mmenuoutbordercolor&&msubedge=="0"){
                      stringx+=';border-right: 1px solid '+mmidincolor+
                      ';border-bottom: 1px solid '+mmidincolor;}
                      stringx+=';border-top: 1px solid '+mmenuoutbordercolor+
                      ';padding: 4px" bgcolor='+mmenucolor+'>n'
                      for(var i=0;i<thismenu.items.length;i++){
                       var thismenuitem=thismenu.items[i];
                       var imgsize="";
                              if(thismenuitem.sizex!="0"||thismenuitem.sizey!="0")imgsize=" width="+thismenuitem.sizex+" height="+thismenuitem.sizey;
                              var ifspace="";
                              if(thismenu.caption!="")ifspace=" ";
                       if(thismenuitem.hasc!=null){
                       stringx += "<tr><td id=mp"+thismenuitem.hasc+" class=coolButton style='border: "+mitemedge+"px solid "+mmenucolor+
                       "' width=100% onmouseout=mmenuitem_out(true) onmouseover="mmenuitem_over(mmenudiv"+x+
                       ",'"+thismenuitem.hasc+"',"+x+",-1,"+i+");mshowsubmenu(msubmenudiv"+thismenuitem.hasc+",mp"+thismenuitem.hasc+",mmenudiv"+x+");""+
                       "><table id=mitem"+thismenuitem.hasc+" cellspacing='0' cellpadding='0' border='0' width='100%' style='"+mfonts+"'><tr><td ";
                         if(thismenuitem.pos=="0"){
                                  stringx += "><img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+">"+ifspace+thismenuitem.caption+"</td><td";
                                }else if(thismenuitem.pos=="1"){
                                  stringx += ">"+thismenuitem.caption+ifspace+"<img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+"></td><td";
                                }else if(thismenuitem.pos=="2"){
                                  stringx += "background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'>"+thismenuitem.caption+"</td><td background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'";
                                }else{
                                  stringx += ">"+thismenuitem.caption+"</td><td";
                                }
                         stringx += " align=right width='1'><font face='Webdings' style='font-size: 6pt'>4</font></td></tr></table></td></tr>n";                      
                       }else if(!thismenuitem.isline){
                       stringx += "<tr><td class=coolButton style='border: "+mitemedge+"px solid "+mmenucolor+
                       "' width=100% height=15px onmouseover="mmenuitem_over(mmenudiv"+x+
                       ",false,"+x+",-1,"+i+");" onmouseout=mmenuitem_out() onmousedown=mmenuitem_down() onmouseup=";
     stringx += "mmenuitem_up();mexec("+x+","+i+"); ";
       if(thismenuitem.pos=="0"){
                                  stringx += "><img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+">"+ifspace+thismenuitem.caption+"</td></tr>";
                                }else if(thismenuitem.pos=="1"){
                                  stringx += ">"+thismenuitem.caption+ifspace+"<img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+"></td></tr>";
                                }else if(thismenuitem.pos=="2"){
                                  stringx += "background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'>"+thismenuitem.caption+"</td></tr>";
                                }else{
                                  stringx += ">"+thismenuitem.caption+"</td></tr>";
                                }
     }else{
                       stringx+='<tr><td height="1" background=http://pic3.phprm.com/2015/07/04/hr.jpg onmousemove="clearTimeout(mpopTimer);"><img height="1" width="1" src="none.gif" border="0"></td></tr>n';
                       }
                      }stringx+='</table>n</div>'
                      }                     
                }
               
for(var j=1;j<=mnumberofsub;j++){    
thisitem=eval("msub"+j);
stringx+='<div id=msubmenudiv'+j+
                        ' style="filter:Alpha(Opacity=80);tag:'+thisitem.level+';cursor:'+mcursor+';position:absolute;'+
                        'width:'+mmenuitemwidth+'px; z-index:'+(j+200);
                        if(mmenuinbordercolor!=mmenuoutbordercolor&&msubedge=="0"){
                        stringx+=';border-left: 1px solid '+mmidoutcolor+
                        ';border-top: 1px solid '+mmidoutcolor;}
                        stringx+=';border-right: 1px solid '+mmenuinbordercolor+
                        ';border-bottom: 1px solid '+mmenuinbordercolor+';visibility:hidden" onselectstart="event.returnValue=false">n'+
                      '<table  width="100%" border="0" height="100%" align="center" cellpadding="0" cellspacing="2" '+
                      'style="'+mfonts+' border-left: 1px solid '+mmenuoutbordercolor;
                      if(mmenuinbordercolor!=mmenuoutbordercolor&&msubedge=="0"){
                      stringx+=';border-right: 1px solid '+mmidincolor+
                      ';border-bottom: 1px solid '+mmidincolor;}
                      stringx+=';border-top: 1px solid '+mmenuoutbordercolor+
                      ';padding: 4px" bgcolor='+mmenucolor+'>n'
                      for(var i=0;i<thisitem.items.length;i++){
                       var thismenuitem=thisitem.items[i];
                       var imgsize="";
                              if(thismenuitem.sizex!="0"||thismenuitem.sizey!="0")imgsize=" width="+thismenuitem.sizex+" height="+thismenuitem.sizey;
                              var ifspace="";
                              if(thismenu.caption!="")ifspace=" ";
                       if(thismenuitem.hasc!=null){
                       stringx += "<tr><td id=mp"+thismenuitem.hasc+" class=coolButton style='border: "+mitemedge+"px solid "+mmenucolor+
                       "' width=100% onmouseout=mmenuitem_out(true) onmouseover="mmenuitem_over(msubmenudiv"+j+
                       ",'"+thismenuitem.hasc+"',-1,"+j+","+i+");mshowsubmenu(msubmenudiv"+thismenuitem.hasc+",mp"+thismenuitem.hasc+",msubmenudiv"+j+");""+
                       "><table id=mitem"+thismenuitem.hasc+" cellspacing='0' cellpadding='0' border='0' width='100%' style='"+mfonts+"'><tr><td ";
                         if(thismenuitem.pos=="0"){
                                  stringx += "><img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+">"+ifspace+thismenuitem.caption+"</td><td";
                                }else if(thismenuitem.pos=="1"){
                                  stringx += ">"+thismenuitem.caption+ifspace+"<img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+"></td><td";
                                }else if(thismenuitem.pos=="2"){
                                  stringx += "background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'>"+thismenuitem.caption+"</td><td background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'";
                                }else{
                                  stringx += ">"+thismenuitem.caption+"</td><td";
                                }
                         stringx += " align=right width='1'><font face='Webdings' style='font-size: 6pt'>4</font></td></tr></table></td></tr>n";                      
                       }else if(!thismenuitem.isline){
                       stringx += "<tr><td class=coolButton style='border: "+mitemedge+"px solid "+mmenucolor+
                       "' width=100% height=15px onmouseover="mmenuitem_over(msubmenudiv"+j+
                       ",false,-1,"+j+","+i+");" onmouseout=mmenuitem_out() onmousedown=mmenuitem_down() onmouseup=";
                       stringx += "mmenuitem_up();mexec3("+j+","+i+"); ";
     if(thismenuitem.pos=="0"){
                                  stringx += "><img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+">"+ifspace+thismenuitem.caption+"</td></tr>";
                                }else if(thismenuitem.pos=="1"){
                                  stringx += ">"+thismenuitem.caption+ifspace+"<img align=absmiddle src='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'"+imgsize+"></td></tr>";
                                }else if(thismenuitem.pos=="2"){
                                  stringx += "background='http://pic3.phprm.com/2015/07/04/"+thismenuitem.jpg'>"+thismenuitem.caption+"</td></tr>";
                                }else{
                                  stringx += ">"+thismenuitem.caption+"</td></tr>";
                                }
                              }else{
                       stringx+='<tr><td height="1" background=http://pic3.phprm.com/2015/07/04/hr.jpg onmousemove="clearTimeout(mpopTimer);"><img height="1" width="1" src="none.gif" border="0"></td></tr>n';
                       }
                      }
stringx+='</table>n</div>'
}
       document.write("<div align='center' id='JsMenuCSS'>"+stringx+"</div>");
}

阅读全文

php图片上传代码


<?php

if(empty($_GET[submit
]))

{

?>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']?>?submit=1" method="post">
Send this file: <input name="filename" type="file">
<input type="submit" value="确定上传">
</form>
<?php 
}else{
    
$path="uploadfiles/";        
//上传路径

//echo $_FILES["filename"]["type"];


if(!file_exists($path
))
{
    
//检查是否有该文件夹,如果没有就创建,并给予最高权限
    
mkdir("$path"0700
);
}
//END IF
//允许上传的文件格式
$tp = array("image/gif","image/pjpeg","image/png"
);
//检查上传文件是否在允许上传的类型
if(!in_array($_FILES["filename"]["type"],$tp
))
{
    echo 
"格式不对"
;
    exit;
}
//END IF
if($_FILES["filename"]["name"
])
{
        
$file1=$_FILES["filename"]["name"
];
        
$file2 $path.time().$file1
;
        
$flag=1
;
}
//END IF
if($flag$result=move_uploaded_file($_FILES["filename"]["tmp_name"],$file2
);
//特别注意这里传递给move_uploaded_file的第一个参数为上传到服务器上的临时文件
if($result
)
{
    
//echo "上传成功!".$file2;
    
echo "<script language='javascript'>"
;
    echo 
"alert("上传成功!");"
;
    echo 
" location='add_aaa.php?pname=$file2'"
;
    echo 
"</script>"
;
}
//END IF


}

?>

阅读全文

动态网页技术PHP中关于类的几点使用技巧

对类的摸索~~俺用了半年时间才大概理解类的作用和实现。主要是没有一篇能让我理解的文章(之前没接触过任何OO的东西)。

  以我的观点来说说PHP中的Class,用于表达的语言都是非正式的语言,也不能确定是否正确。

  建立一个类很简单:

class my_class {}

  类到底干什么呢?很多人都说是什么黑匣子,我在这里称它为一个独立的整体。我们只知道类名,而不知道里面有什么东西。那么,该如何使用这个类呢?

  首先:要知道它里面是否定义了公共的变量--专业术语上称它为“属性”。
  其次:要知道它里面定义了什么函数--专业术语中称它为“方法”。
  我都被这些专业术语搞糊涂了,所以干脆不理它了。

  类中的如何定义公共变量,它有什么作用呢?

  很简单,我们来扩充 my_class 类:

class my_class
{
var $username;
}

  看上面很简单,我们定义了一个公共的变量,只是用 var 空格 普通变量名构成。它有什么用呢?考虑一下函数中,假如我们要访问函数外的变量,是不是要先 global 一下呢?这个想实现的效果也是如此,它是想让这个类中的所有函数都能访问它,而它区别于函数的一个地方,是类的外部也可以随时访问和控制这个变量,我随后再讲外部如何访问它。还有一个区别,不能用复杂的语句给这个变量赋值(具体的等理解了类以后自己去看规则)。

  给它一个默认值:

class my_class
{
var $username = "深空";
}

OK,定义了一个公共的变量了,接下来定义一个函数(也就是所谓的“方法”):

class my_class
{
var $username = "深空";

function show_username()
{
}
}

这个定义函数跟普通的定义函数形式上没什么区别了。简单就好,定义一个打印 $username 的函数:

class my_class
{
var $username = "深空";

function show_username($username)
{
echo $username;
}
}

  到这里可能某些人开始迷糊了,呵呵,最要害的就是这里了,看清楚了。现在有三个 $username 了。到底哪个是哪个啊~~

阅读全文

动态网页制作PHP常用的正则表达式

匹配中文字符的正则表达式: [u4e00-u9fa5]

  匹配双字节字符(包括汉字在内): [^x00-xff]

  应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

String.prototype.len=function(){return this.replace([^x00-xff]/g,"aa").length;}

  匹配空行的正则表达式: n[s| ]*r

  匹配HTML标记的正则表达式: /<(.*)>.*</>|<(.*) />/

  匹配首尾空格的正则表达式: (^s*)|(s*$)

  应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:

String.prototype.trim = function() {
return this.replace(/(^s*)|(s*$)/g, "");
}

  利用正则表达式分解和转换IP地址:

  下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的javascript程序:

function IP2V(ip) {
re=/(d ).(d ).(d ).(d )/g //匹配IP地址的正则表达式
if(re.test(ip)) {
return RegExp.*Math.pow(255,3)) RegExp.*Math.pow(255,2)) RegExp.*255 RegExp.*1
}
else {
throw new Error("Not a valid IP address!")
}
}

  不过上面的程序假如不用正则表达式,而直接用split函数来分解可能更简单,程序如下:

var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:" (ip[0]*255*255*255 ip[1]*255*255 ip[2]*255 ip[3]*1))

  匹配Email地址的正则表达式: w ([- .]w )*@w ([-.]w )*.w ([-.]w )*

  匹配网址URL的正则表达式: http://([w-] .) [w-] (/[w- ./?%&=]*)?

  利用正则表达式去除字串中重复的字符的算法程序:

var s="abacabefgeeii"
var s1=s.replace(/(.).*/g,"")
var re=new RegExp("[" s1 "]","g")
var s2=s.replace(re,"")
alert(s1 s2) //结果为:abcefgi

  用正则表达式从URL地址中提取文件名的javascript程序,如下结果为page1

s="http://www.etoow.com/page1.htm"
s=s.replace(/(.*/)([^.] ).*/ig,"")
alert(s)

  利用正则表达式限制网页表单里的文本框输入内容:

  用正则表达式限制只能输入中文:

onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"

  用正则表达式限制只能输入全角字符:

onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"

  用正则表达式限制只能输入数字:

onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"

  用正则表达式限制只能输入数字和英文:

onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,'')

阅读全文

详细阐述PHP环境下如何将GBK编码转成UTF-8格式

apache 字符集 GB 2312
mysql 字符集 GBK
现要从 mysql 中提出信息(GBK) 写入到 XML 中
XML中的编码格式是 UTF-8

那么,如何将GBK编码成 UTF8 ??

具体介绍:
前一阵子见到了qiushuiwuhen君的关于gbk,unicode,big5的转换的文章
但是多少有一些不太大的问题

于是我设计了一个负责字符转换的类,修正了其中的一些不足,增加了部分功能,以后我会不断扩充该类,来支持更多的字符集

增加了如下几点:

unicode->gbk 符号部分的转换
欧元符的识别
big5,Unicode,GBK之间的相互转换,前提是只转换共同的字符集部分,

使用说明:
暂时程序支持以下字符编码方式:
GBK,BIG5,UTF-16BE(Unicode big-endian字节顺序),UTF-16LE(Unicode little-endian字节顺序),UTF-8
默认输入编码方式为GBK,默认输出编码方式为UTF-16BE;
该类别提供两个函数用来修改输入和输出编码方式:
修改输入编码方式 boolean SetGetEncoding(string $GetEncoding)
修改输出编码方式 boolean SetToEncoding(string $ToEncoding)
函数参数只能使用上述5种编码方式,区分大小写,如GBK不能写成gbk
假如设置成功,返回true,假如使用了错误的编码名,返回false,并现实错误信息

函数
string EncodeString(string $String)
负责进行字符编码转换,返回转换后的字符串

使用前,请将var $FilePath=""变量该为该程序文件的绝对路径,否则将会找不到数据文件

例子:
将gbk编码的字符串转化为UTF-8编码:

$s="GBK编码";
$CharEncoding=new Encoding();
$CharEncoding->SetGetEncoding("GBK")||die("编码名错误");
$CharEncoding->SetToEncoding("UTF-8")||die("编码名错误");
echo $CharEncoding->EncodeString($s);

在浏览器中使用UTF-8编码察看,将会看到正确的字符

阅读全文

下拉透明菜单二

function mMenu(caption,command,target,img,sizex,sizey,pos){
 this.items = new Array();
 this.caption=caption;
 this.command=command;
 this.target=target;
 this.img=img;
 this.sizex=sizex;
 this.sizey=sizey;
 this.pos=pos;
 this.id=mMenuRegister(this);
}
function mMenuAddItem(item)
{
  this.items[this.items.length] = item
  item.parent = this.id;
  this.children=true;
}

阅读全文

PHP套接字编程

套接字编程,一般使用c或c 。非凡的在web应用程序开发中,常用perl实现套接字。除此以外,用php进行套接字编程也是一个选择。Php可以胜任吗?当然可以。Php是一门高质量的web应用程序开发语言,他的许多特性可以处理众多的任务,网络编程也不例外。

1. 理解套接字
Mail、ftp、telnet、name和finger这些服务都是在一个专用的公开的端口上提供的,通过连接到这些端口,客户程序就能够访问这些服务。这与现实生活是相似的

阅读全文

下拉透明菜单一部分

下拉透明菜单


<script language="JavaScript">
var mmenus    = new Array();
var misShow   = new Boolean();
misShow=false;
var misdown   = new Boolean();
misdown=false;
var mnumberofsub=0;
var musestatus=false;
var mpopTimer = 0;
mmenucolor='#89CB10';mfontcolor='MenuText';mmenuoutcolor='#ADEF34';mmenuincolor='#B5E74E';mmenuoutbordercolor='#ECFA3A';mmenuinbordercolor='#5A2614';mmidoutcolor='#A9DA1D';mmidincolor='#799310';mmenuovercolor='#004080';mitemedge='0';msubedge='1';mmenuunitwidth=66;mmenuitemwidth=140;mmenuheight=25;mmenuwidth='100%';mmenuadjust=0;mmenuadjustV=0;mfonts='font-family: 宋体; font-size: 9pt; color: MenuText; ';mcursor='hand';
var swipeSteps = 4;
var swipemsec = 25;
var swipeArray = new Array();
function swipe(el, dir, steps, msec) {
 if (steps == null) steps = swipeSteps;
 if (msec == null) msec = swipemsec;
 if (el.swipeIndex == null)
  el.swipeIndex = swipeArray.length;
 if (el.swipeTimer != null)
  window.clearTimeout(el.swipeTimer);
 swipeArray[el.swipeIndex] = el;
 el.style.clip = "rect(-99999, 99999, 99999, -99999)";
 if (el.swipeCounter == null || el.swipeCounter == 0) {
  el.orgLeft  = el.offsetLeft;
  el.orgTop  = el.offsetTop;
  el.orgWidth = el.offsetWidth;
  el.orgHeight  = el.offsetHeight;
 }
 el.swipeCounter = steps;
 el.style.clip = "rect(0,0,0,0)";
 window.setTimeout("repeat(" + dir + "," + el.swipeIndex + "," + steps + "," + msec + ")", msec);
}
function repeat(dir, index, steps, msec) {
 el = swipeArray[index];
 var left   = el.orgLeft;
 var top    = el.orgTop;
 var width  = el.orgWidth;
 var height = el.orgHeight;
 if (el.swipeCounter == 0) {
  el.style.clip = "rect(-99999, 99999, 99999, -99999)";
  return;
 }
 else {
  el.swipeCounter--;
  el.style.visibility = "visible";
  switch (dir) {
   case 2:
    el.style.clip = "rect(" + height*el.swipeCounter/steps + "," + width + "," + height + "," + 0 + ")";
    el.style.top  = top - height*el.swipeCounter/steps;
    break;
   case 8:
    el.style.clip = "rect(" + 0 + "," + width + "," + height*(steps-el.swipeCounter)/steps + "," + 0 + ")";
    el.style.top  = top + height*el.swipeCounter/steps;
    break;
   case 6:
    el.style.clip = "rect(" + 0 + "," + width + "," + height + "," + width*(el.swipeCounter)/steps + ")";
    el.style.left  = left - width*el.swipeCounter/steps;
    break;
   case 4:
    el.style.clip = "rect(" + 0 + "," + width*(swipeSteps - el.swipeCounter)/steps + "," + height + "," + 0 + ")";
    el.style.left  = left + width*el.swipeCounter/steps;
    break;
  }
 
  el.swipeTimer = window.setTimeout("repeat(" + dir + "," + index + "," + steps + "," + msec + ")", msec);
 }
}
var mtmpleft="";
var mtmptop="";
function hideSwipe(el) {
 window.clearTimeout(el.swipeTimer);
 el.style.visibility = "hidden";
 el.style.clip = "rect(-99999, 99999, 99999, -99999)";
 el.swipeCounter = 0;
 if(mtmpleft!="")el.style.left = mtmpleft;
 if(mtmptop!="")el.style.top = mtmptop;
}

阅读全文

php 简单清析文件上传

function Uploadfile(){
   //文件保存目录路径
   $save_path = '../upload/';
   //定义允许上传的文件扩展名
   $ext_arr = array('rar','zip');
   //最大文件大小
   $max_size = 1000000;
   //更改目录权限
   @mkdir($save_path, 0777);
   
   
   //有上传文件时
   if (empty($_FILES) === false) {
    //原文件名
    $file_name = $_FILES['fileData']['name'];
    //服务器上临时文件名
    $tmp_name = $_FILES['fileData']['tmp_name'];
    //文件大小
    $file_size = $_FILES['fileData']['size'];
    //检查目录
    if (@is_dir($save_path) === false) {
     alert("上传目录不存在。");
    }
    //检查目录写权限
    if (@is_writable($save_path) === false) {
     alert("上传目录没有写权限。");
    }
    //检查是否已上传
    if (@is_uploaded_file($tmp_name) === false) {
     alert("临时文件可能不是上传文件。");
    }
    //检查文件大小
    if ($file_size > $max_size) {
     alert("上传文件大小超过限制。");
    }
    //获得文件扩展名
    $temp_arr = explode(".", $file_name);
    $file_ext = array_pop($temp_arr);
    $file_ext = trim($file_ext);
    $file_ext = strtolower($file_ext);
    //检查扩展名
    if (in_array($file_ext, $ext_arr) === false) {
     alert("上传文件扩展名是不允许的扩展名。");
    }
    //移动文件
    if (move_uploaded_file($tmp_name, $file_path) === false) {
     alert("上传文件失败。");
    }
 } 

阅读全文