#1 logoove
//常用函数Fn,使用import(APP_PATH.'/SpeedPHP/Extensions/Fn.php');/**
* 生成随机数
*/
function getRandom($min, $max)
{
srand((double)microtime() * 1000000);
$randval = rand($min, $max);
return $randval;
}
/**
* 获取服务器当前日期时间
*/
function getDateTime()
{
date_default_timezone_set("Asia/Chongqing");
return date("Y-m-d H:i:s");
}
/**
* 获取服务器当前日期
*/
function getDater()
{
date_default_timezone_set("Asia/Chongqing");
return date("Y-m-d");
}
/**
* 获取服务器当前时间
*/
function getTime()
{
date_default_timezone_set("Asia/Chongqing");
$timeval["h"] = date("h"); //小时
$timeval["i"] = date("i"); //分钟
$timeval["s"] = date("s"); //秒
return $timeval;
}
/**
* 获取倒计时剩余时间
* 参数 t 秒钟偏移量 默认为0
*/
function getcT($t = 0)
{
$time =getTime();
$s = (3 - $time["i"] % 3) * 60 - $time["s"] + $t;
return $s;
}
/**
* 验证邮箱地址格式
*/
function isEmail($email)
{
if (preg_match("/[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,4}/",$email,$mail))
{
return true;
}
else
{
return false;
}
}
/**
* 验证用户名是否以字母开头
*/
function isUserNum($user)
{
if (preg_match("/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){3,19}$/",$user,$username))
{
return true;
}
else
{
return false;
}
}
/**
* 验证密码只能为数字和字母的组合
*/
function isPsd($psd)
{
if (preg_match("/^(\w){4,20}$/",$psd,$password))
{
return true;
}
else
{
return false;
}
}
/**
* 转跳到url
*/
function url($url)
{
$code="";
return $code;
}
function toUrl($url="index.php",$info = "页面转向中...",$second=2){
print "
print "";
print '';
print '';
print '
"; | |||
"; print '
| "; |||
'; |
print "";
exit;
}
/**
* 弹出js提示框
*/
function msg($content)
{
$code="";
return $code;
}
/**
* 返回上一页
*/
function back()
{
$code="返回";
return $code;
}
/**
* 获取用户真实IP
*/
function getIP()
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
if ($_SERVER["HTTP_CLIENT_IP"])
{
$proxy = $_SERVER["HTTP_CLIENT_IP"];
}
else
{
$proxy = $_SERVER["REMOTE_ADDR"];
}
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else
{
if (isset($_SERVER["HTTP_CLIENT_IP"]))
{
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
else
{
$ip = $_SERVER["REMOTE_ADDR"];
}
}
return $ip;
}
/**
* 处理提交数据中的HTML代码
*/
function clearHTML($val)
{
return ltrim(chop(htmlspecialchars($val)));
}
/**
* 获取字符长度
*/
function getStrLen($str)
{
return mb_strlen($str,"UTF8");
}
/**
* 创建多级目录
*/
function createDir($dir)
{
if(!is_dir($dir))
{
if(!createDir(dirname($dir)))
{
return false;
}
if(!mkdir($dir,0777))
{
return false;
}
}
return true;
}
/**
* 字符串截取
*/
function strSub($string, $sublen, $start)
{
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
return join('', array_slice($t_string[0], $start, $sublen));
}
/**
* 字符串分割
* $str2: 分割标识符
*/
function strExplode($str1,$str2)
{
$array=explode($str2,$str1);
return $array;
}
/**
* 数组
* $str_2:连接标识符
*/
function strImplode($str_1,$str_2)
{
$string=implode($str_2,$str_1);
return $string;
}
/**
* 检查发帖间隔
*/
function cTtime($iTime=intervalTime)
{
if(isset($_SESSION['post_time']))
{
if (time()-$_SESSION['post_time']>60*$iTime)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
/**
* 字符串替换
*/
function strReplace($str)
{
$str=str_replace("<","<",$str);
$str=str_replace(">",">",$str);
$str=str_replace("object","",$str);
$str=str_replace("script","",$str);
return $str;
}
/**
* 清空字符串中的HTML标签
*/
function clearLabel($html)
{
$search = array ("''si", "'<[/!]*?[^<>]*?>'si", "'([rn])
$replace = array ("", "", "\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\1)");
return preg_replace($search, $replace, $html);
}
/**
* 取整数
* (4舍5入)
*/
function getInt($num)
{
if(ceil($num)==$num)
{
return $num;
}
else
{
$num=explode(".",$num);
if(strSub($num[1],1,0)>=5)
{
$num[0]+=1;
}
return $num[0];
}
}
/**
* 取整数
*/
function getInt0($num)
{
if(ceil($num)==$num)
{
return $num;
}
else
{
$num=explode(".",$num);
return $num[0];
}
}
/**
* 取小数
*/
function getDec($num)
{
if(ceil($num)==$num)
{
return "0.0";
}
else
{
$num=explode(".",$num);
return "0.".(double)$num[1];
}
}
function isExists($filename1='') //检查目录或文件是否存在
{
if(file_exists($filename1))
{
return true;
}
else return false;
}
function createDir0($dirname,$mode=0777) // 一次只能创建一级目录,成功返回1
{
if(is_null($dirname) || $dirname=="") return false;
if(!is_dir($dirname))
{
return mkdir($dirname,$mode);
}
}
function delDir($dirname) //删除目录包括有文件
{
if(isExists($dirname) and is_dir($dirname))
{
if(!$dirhandle=opendir($dirname)) return false;
while(($file=readdir($dirhandle))!==false)
{
if($file=="." or $file=="..") continue;
$file=$dirname.DIRECTORY_SEPARATOR.$file; //表示$file是$dir的子目录
if(is_dir($file))
{
delDir($file);
}
else
{
unlink($file);
}
}
closedir($dirhandle);
return rmdir($dirname);
}
else return false;
}
function copyDir($dirfrom,$dirto) //复制目录,包括文件
{
if(!is_dir($dirfrom)) return false;
if(!is_dir($dirto)) mkdir($dirto);
$dirhandle=opendir($dirfrom);
if($dirhandle)
{
while(false!==($file=readdir($dirhandle)))
{
if($file=="." or $file=="..") continue;
$filefrom=$dirfrom.DIRECTORY_SEPARATOR.$file; //表示$file是$dir的子目录
$fileto=$dirto.DIRECTORY_SEPARATOR.$file;
if(is_dir($filefrom))
{
copyDir($filefrom,$fileto);
}
else
{ if(!file_exists($fileto))
copy($filefrom,$fileto);
}
}
}
closedir($dirhandle);
}
多余的不说,可以放到插件目录,然后导入php文件,这里没有做成类关键是里面有些很常用,函数用起来更方便
2011-05-14 21:34:43