/** * 计算几分钟前、几小时前、几天前、几月前、几年前。 * $agoTime string Unix时间 * @author tangxinzhuan * @version 2016-10-28 */ function smartDate($agoTime) { $agoTime = (int)$agoTime; // 计算出当前日期时间到之前的日期时间的毫秒数,以便进行下一步的计算 $time = time() - $agoTime; if ($time >= 31104000) { // N年前 ...
/** * 页面跳转 */ function emDirect($directUrl) { header("Location: $directUrl"); exit; }
/** * 删除文件或目录 */ function emDeleteFile($file) { if (empty($file)) return false; if (@is_file($file)) return @unlink($file); $ret = true; if ($handle = @opendir($file)) { while ($filename = @readdir($handle)) { if ($filename == '.' || $filename...
/** * 生成一个随机的字符串 * * @param int $length * @param boolean $special_chars * @return string */ function getRandStr($length = 12, $special_chars = true) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()';...
/** * 获取文件名后缀 */ function getFileSuffix($fileName) { return strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); }
/** * 转换附件大小单位 * * @param string $fileSize 文件大小 kb */ function changeFileSize($fileSize) { if ($fileSize >= 1073741824) { $fileSize = round($fileSize / 1073741824, 2) . 'GB'; } elseif ($fileSize >= 1048576) { $fileSize = round($fileSize / 1048576, 2) . 'MB'; ...
/**截取编码为utf8的字符串 *@param string $strings 预处理字符串@param int $start 开始处 eg:0@param int $length 截取长度 */function subString($strings, $start, $length) {if (function_exists('mb_substr') && function_exists('mb_strlen')) { $sub_str = mb_substr($strings, $start, $length, 'utf8'); return mb_...
/** * 验证email地址格式 */ function checkMail($email) { if (preg_match("/^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/", $email) && strlen($email) <= 60) { return true; } else { return false; } }
/** * 检测是否为IP * @param [type] $ip [description] * @return [type] [description] */ function funip($ip){ //IP正则匹配 //0.0.0.0--- 255.255.255.255 $pat = "/^(((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))$/"; if(preg_match($pat,$ip)){ $...
/** * 转换HTML代码函数 * * @param unknown_type $content * @param unknown_type $wrap 是否换行 */ function htmlClean($content, $nl2br = true) { $content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); if ($nl2br) { $content = nl2br($content); } $content = str_replace(' ', '&a...