date("Y-m-d",strtotime($date[1]))){ return "end"; }elseif($today>=date("Y-m-d",strtotime($date[0]))&&$today<=date("Y-m-d",strtotime($date[1]))){ return "doing"; }elseif($today".$date[1]; } } function getTrainTime($date=""){ $date=explode(":", $date); $today=date("Y-m-d"); if($today>date("Y-m-d",strtotime($date[1]))){ return "

结束 ".$date[1]."

"; }elseif($today>=date("Y-m-d",strtotime($date[0]))&&$today<=date("Y-m-d",strtotime($date[1]))){ return "进行中"; }elseif($today报名中

截止".date('Y-m-d',$time)."

"; }else{ "已结束
".$date[1]; } } function getTrainTime2($date=""){ $date=explode(":", $date); $today=date("Y-m-d"); if($today>date("Y-m-d",strtotime($date[1]))){ return "

结束 ".$date[1]."

"; }elseif($today>=date("Y-m-d",strtotime($date[0]))&&$today<=date("Y-m-d",strtotime($date[1]))){ return ""; //return "进行中"; }elseif($today截止".date('Y-m-d',$time)."

"; }else{ "结束
".$date[1]; } } function getTrainTime3($date=""){ $date=explode(":", $date); $today=date("Y-m-d"); if($today>date("Y-m-d",strtotime($date[1]))){ return '已结束 '.$date[1]; }elseif($today>=date("Y-m-d",strtotime($date[0]))&&$today<=date("Y-m-d",strtotime($date[1]))){ return '正在进行'; }elseif($today报名中 截止 '.$date[1]; }else{ return '已结束 '.$date[1]; } } function getTrainTimeTk($date=""){ $date=explode(":", $date); $today=date("Y-m-d"); if($today>date("Y-m-d",strtotime($date[1]))){ return "结束 ".$date[1]; }elseif($today>=date("Y-m-d",strtotime($date[0]))&&$today<=date("Y-m-d",strtotime($date[1]))){ return "进行中"; }elseif($today报名中 截止".date('Y-m-d',$time); }else{ "已结束  ".$date[1]; } } function getColumnType($c_type=1){ if($c_type==1) return "系统"; elseif ($c_type==2) return "链接"; elseif ($c_type==3) return "介绍"; } /** * 获取上一页 * @param unknown_type $on_page */ function get_previous($on_page = 1) { return $on_page != 0 ? $on_page - 1 : $on_page; } /** * 获取几个小时后的时间戳 * @param unknown_type $hours */ function get_hours($hours = 0) { if ($hours != 0) return strtotime ( "+" . $hours . " hours" ); return strtotime ( "now" ); } /** * 获取几个分钟后的时间戳 * @param unknown_type $hours */ function get_seconds($seconds = 0) { if ($seconds != 0) return strtotime ( "+" . $seconds . " seconds" ); return strtotime ( "now" ); } /** * 获取时间戳 */ function get_time($time = 0) { return strtotime ( $time ); } /** * 格式化时间为年月日时分秒 * @param unknown_type $strtotime */ function format_time($strtotime = 0, $format = "Y-m-d H:i:s") { return date ( $format, $strtotime ); } /** * 获取客户端IP地址 */ function client_ip() { if (getenv ( 'HTTP_CLIENT_IP' ) && strcasecmp ( getenv ( 'HTTP_CLIENT_IP' ), 'unknown' )) { $onlineip = getenv ( 'HTTP_CLIENT_IP' ); } elseif (getenv ( 'HTTP_X_FORWARDED_FOR' ) && strcasecmp ( getenv ( 'HTTP_X_FORWARDED_FOR' ), 'unknown' )) { $onlineip = getenv ( 'HTTP_X_FORWARDED_FOR' ); } elseif (getenv ( 'REMOTE_ADDR' ) && strcasecmp ( getenv ( 'REMOTE_ADDR' ), 'unknown' )) { $onlineip = getenv ( 'REMOTE_ADDR' ); } elseif (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], 'unknown' )) { $onlineip = $_SERVER ['REMOTE_ADDR']; } preg_match ( '/[\d\.]{7,15}/', $onlineip, $onlineipmatches ); $onlineip = ($onlineipmatches [0] ? $onlineipmatches [0] : 'unknown'); return $onlineip; } /** * random 获取字符串 * @param int $length * @return string $hash */ function random($length = 6, $type = 0) { $hash = ''; $chararr = array ('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz', '0123456789', '23456789ABCDEFGHJKLMNPQRSTUVWXYZ' ); $chars = $chararr [$type]; $max = strlen ( $chars ) - 1; PHP_VERSION < '4.2.0' && mt_srand ( ( double ) microtime () * 1000000 ); for($i = 0; $i < $length; $i ++) { $hash .= $chars [mt_rand ( 0, $max )]; } return $hash; } /** * 多少天以前 */ function day_ago($day = 7) { $now = strtotime ( "now" ); } /** * 获取天数差 * @param unknown_type $nowtime 现在时间 * @param unknown_type $future 过去时间 */ function count_days($nowtime, $futuretime) { $a_dt = getdate ( $nowtime ); $b_dt = getdate ( $futuretime ); $a_new = mktime ( 12, 0, 0, $a_dt ['mon'], $a_dt ['mday'], $a_dt ['year'] ); $b_new = mktime ( 12, 0, 0, $b_dt ['mon'], $b_dt ['mday'], $b_dt ['year'] ); return round ( abs ( $a_new - $b_new ) / 86400 ); } function my_date_format($timestamp, $format = "Y-m-d H:i:s") { $SystemConfig = ConfigHandler::get (); $timezone = $SystemConfig ['timezone']; return gmdate ( $format, ($timestamp + $timezone * 3600) ); } //格式化时间函数 function my_date_format2($time = 0, $format = 'Y-m-d') { $time = isset ( $time ) ? $time : 0; $now = time (); $t = $now - $time; if ($t < 0) { $time = format_date ( $time, $format ); return $time; } if ($t >= 3600) { $time = format_date ( $time, $format ); } elseif ($t < 3600 && $t >= 60) { $time = floor ( $t / 60 ) . "分钟前"; } else { $time = "刚刚"; } return $time; } /** * 获取文件后缀名 * @param unknown_type $filename */ function _GetFileEXT($filename) { $pics = explode ( '.', $filename ); $num = count ( $pics ); return $pics [$num - 1]; } /** * 加密或解密指定字符串 * @param string $string 要加密或解密的字符串 * @param string $operation 当取值为'DECODE'时表示解密,否则为加密 * @param string $key 加解密的key * @param $expiry 超时值 * */ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; if (! $key) { $key = AUTH; } $key = md5 ( $key ); $keya = md5 ( substr ( $key, 0, 16 ) ); $keyb = md5 ( substr ( $key, 16, 16 ) ); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : ''; $cryptkey = $keya . md5 ( $keya . $keyc ); $key_length = strlen ( $cryptkey ); $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string; $string_length = strlen ( $string ); $result = ''; $box = range ( 0, 255 ); $rndkey = array (); for($i = 0; $i <= 255; $i ++) { $rndkey [$i] = ord ( $cryptkey [$i % $key_length] ); } for($j = $i = 0; $i < 256; $i ++) { $j = ($j + $box [$i] + $rndkey [$i]) % 256; $tmp = $box [$i]; $box [$i] = $box [$j]; $box [$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i ++) { $a = ($a + 1) % 256; $j = ($j + $box [$a]) % 256; $tmp = $box [$a]; $box [$a] = $box [$j]; $box [$j] = $tmp; $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) ); } if ($operation == 'DECODE') { if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) { return substr ( $result, 26 ); } else { return ''; } } else { return $keyc . str_replace ( '=', '', base64_encode ( $result ) ); } } /** * 将一个字符串写入文件 * @param string $filename 文件名 * @param string $data 要写入文件的内容 * @param mixed $flag 文件的写入标识,如果为FILE_APPEND或'FILE_APPEND'表示追加,否则为新建 * @return int 返回写入文件的字节数 * */ function files_put_contents($filename, $data, $flag = false) { $mode = ($flag == FILE_APPEND || strtoupper ( $flag ) == 'FILE_APPEND') ? 'ab' : 'wb'; $f = @fopen ( $filename, $mode ); if ($f === false) { return 0; } else { if (is_array ( $data )) { $data = implode ( '', $data ); } $bytes_written = @fwrite ( $f, $data ); @fclose ( $f ); return $bytes_written; } } function cut_str($string, $length, $dot = ' ...') { if (strlen ( $string ) <= $length) { return $string; } $strcut = ''; $sys_config = "utf-8"; if (strtolower ( $sys_config ) == 'utf-8') { $n = $tn = $noc = 0; while ( $n < strlen ( $string ) ) { $t = ord ( $string [$n] ); if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n ++; $noc ++; } elseif (194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif (224 <= $t && $t < 239) { $tn = 3; $n += 3; $noc += 2; } elseif (240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif (248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif ($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n ++; } if ($noc >= $length) { break; } } if ($noc > $length) { $n -= $tn; } $strcut = substr ( $string, 0, $n ); } else { for($i = 0; $i < $length; $i ++) { $strcut .= ord ( $string [$i] ) > 127 ? $string [$i] . $string [++ $i] : $string [$i]; } } return $strcut . $dot; } function cutstr($string, $length, $dot = '') { Return cut_str ( $string, $length, $dot ); } ; ?>