标签:
/**
* 检查邮箱是否有效
* @param $email 要检查的邮箱
* @param 返回结果
*/
function isemail($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
/**
* 产生随机码
* @param $length - 要多长
* @param $numberic - 数字还是字符串
* @return 返回字符串
*/
function random($length, $numeric = 0) {
PHP_VERSION < ‘4.2.0‘ && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf(‘%0‘.$length.‘d‘, mt_rand(0, pow(10, $length) - 1));
} else {
$hash = ‘‘;
$chars = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz‘;
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
/**
* 删除非空目录
* @param $path 目录
*/
function removedir($dirname, $keepdir = FALSE) {
$dirname = wipespecial($dirname);
if(!is_dir($dirname)) {
return FALSE;
}
$handle = opendir($dirname);
while(($file = readdir($handle)) !== FALSE) {
if($file != ‘.‘ && $file != ‘..‘) {
$dir = $dirname . DIRECTORY_SEPARATOR . $file;
is_dir($dir) ? removedir($dir) : unlink($dir);
}
}
closedir($handle);
return !$keepdir ? (@rmdir($dirname) ? TRUE : FALSE) : TRUE;
}
标签:
原文地址:http://www.cnblogs.com/amw863/p/4846285.html