function destroyDir($dir, $virtual = false)
{
$ds = DIRECTORY_SEPARATOR;
$dir = $virtual ? realpath($dir) : $dir;
$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;
if (is_dir($dir) && $handle = opendir($dir))
{
while ($file = readdir($handle))
{
if ($file == '.' || $file == '..')
{
continue;
}
elseif (is_dir($dir.$ds.$file))
{
destroyDir($dir.$ds.$file);
}
else
{
unlink($dir.$ds.$file);
}
}
closedir($handle);
rmdir($dir);
return true;
}
else
{
return false;
}
}
php随机生成字符串与随机读取字符串
function readable_random_string($length = 6){
$conso=array("b","c","d","f","g","h","j","k","l",
"m","n","p","r","s","t","v","w","x","y","z");
$vocal=array("a","e","i","o","u");
$password="";
srand ((double)microtime()*1000000);
$max = $length/2;
for($i=1; $i<=$max; $i++)
{
$password.=$conso[rand(0,19)];
$password.=$vocal[rand(0,4)];
}
return $password;
}
PHP验证邮件地址实例
电子邮件验证也许是中最常用的网页表单验证,此代码除了验证电子邮件地址,也可以选择检查邮件域所属 DNS 中的 MX 记录,使邮件验证功能更加强大。
php Cannot send session cache limiter
Cannot send session cache limiter
/*
php 字符操作类实例函数
class String extends stdClass
{
private $_val ='';
public function __construct( $str ='' )
{
$this->_val = $str;
}
public function __toString()
{
return $this->_val;
}
public function encode( $coder )
{
$coder ='encode_' . $coder;
if( method_exists( $this, $coder ) )
{
return $this->$coder();
}else{
return $this;
}
}
public function decode( $coder )
{
$coder ='decode_' . $coder;
if( method_exists( $this, $coder ) )
{
return $this->$coder();
}else{
return $this;
}
}
private function encode_md5()
{
return new String( md5( $this->_val ) );
}
private function decode_gbk()
{
return new String( iconv('GBK','UTF-8', $this->_val ) );
}
}
ajax无刷新更新数据
<table class="table_list" >
<caption>
填写要更新的数据
</caption>
<tr>
<td class="align_c">无刷新保存</td>
<td >
<label>
<input name="ajaxdata" type="text" size="20" id="ajaxdata"/>
</label></td>
</tr>
<tr>
<td width="29%" class="align_c"> </td>
<td width="71%" ><label>
<input type="submit" name="button" onclick="return save();" value="提交" />
php 判断上传文件的文件类型多种实例代码
$array = array('jpg','gif','png','jpeg');
$picImg ='/upfile/upload_pic/thumbnail_1258615556.jpg';
php file_put_contents 函数
file_put_contents() 函数把一个字符串写入文件中 与依次调用 fopen(),fwrite() 以及 fclose() 功能一样
说明
参数 data 可以是数组(但不能是多维数组)。
自 PHP 5.1.0 起,data 参数也可以被指定为 stream 资源,stream 中所保存的缓存数据将被写入到指定文件中,这种用法就相似于使用 stream_copy_to_stream() 函数。
对 context 参数的支持是 PHP 5.0.0 添加的。
返回值
该函数将返回写入到文件内数据的字节数。