#----------------------------------- 检测函数 Start ----------------------------#
#风逍遥添加于2006-3-26
#
#-----------------------------------------------------------------------------------//短时间,形如 (13:04:06)
function isTime($str)
{
//$matches = Array ( [0] => 20:02:28 [1] => 20 [2] => : [3] => 02 [4] => 28 )
$s = preg_match('/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( $matches[3]>60 || $matches[5]>60 || $matches[1]>24 )return False; return sprintf("%02d:%02d:%02d", $matches[1], $matches[3], $matches[5]);
}
//短日期,形如 (2003-12-05)
function isDate($str)
{
//$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/', $str, $matches);
//$matches = Array ( [0] => 2006-02-28 [1] => 2006 [2] => - [3] => 02 [4] => - [5] => 28 )
$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})(-|\/)(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( False === checkdate ($matches[3], $matches[5], $matches[1]) )return False; return sprintf("%04d-%02d-%02d", $matches[1], $matches[3], $matches[5]);
}
//长时间,形如 (2003-12-05 13:04:06)
function isDateTime($str)
{
//$matches = Array ( [0] => 2003-12-05 20:2:28 [1] => 2003 [2] => - [3] => 12 [4] => 05 [5] => 20 [6] => : [7] => 2 [8] => 28 )
$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2})(:)?(\d{1,2})\6(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( False === checkdate ($matches[3], $matches[4], $matches[1]) )return False;
if( $matches[5]>24 || $matches[7]>60 || $matches[8]>60 )return False; return sprintf("%04d-%02d-%02d %02d:%02d:%02d", $matches[1], $matches[3], $matches[4], $matches[5], $matches[7], $matches[8]);
}#----------------------------------- 检测函数 End ------------------------------
#风逍遥添加于2006-3-26
#
#-----------------------------------------------------------------------------------//短时间,形如 (13:04:06)
function isTime($str)
{
//$matches = Array ( [0] => 20:02:28 [1] => 20 [2] => : [3] => 02 [4] => 28 )
$s = preg_match('/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( $matches[3]>60 || $matches[5]>60 || $matches[1]>24 )return False; return sprintf("%02d:%02d:%02d", $matches[1], $matches[3], $matches[5]);
}
//短日期,形如 (2003-12-05)
function isDate($str)
{
//$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/', $str, $matches);
//$matches = Array ( [0] => 2006-02-28 [1] => 2006 [2] => - [3] => 02 [4] => - [5] => 28 )
$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})(-|\/)(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( False === checkdate ($matches[3], $matches[5], $matches[1]) )return False; return sprintf("%04d-%02d-%02d", $matches[1], $matches[3], $matches[5]);
}
//长时间,形如 (2003-12-05 13:04:06)
function isDateTime($str)
{
//$matches = Array ( [0] => 2003-12-05 20:2:28 [1] => 2003 [2] => - [3] => 12 [4] => 05 [5] => 20 [6] => : [7] => 2 [8] => 28 )
$s = preg_match('/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2})(:)?(\d{1,2})\6(\d{1,2})$/', $str, $matches); if( empty($s) )return False;
if( False === checkdate ($matches[3], $matches[4], $matches[1]) )return False;
if( $matches[5]>24 || $matches[7]>60 || $matches[8]>60 )return False; return sprintf("%04d-%02d-%02d %02d:%02d:%02d", $matches[1], $matches[3], $matches[4], $matches[5], $matches[7], $matches[8]);
}#----------------------------------- 检测函数 End ------------------------------
.....
if isdate(xx) then ...
$parts = explode($sep,$ymd);
$year = $parts[0];
$month = $parts[1];
$day = $parts[2]; if(isint($year) && isint($month) && isint($day)){
if(checkdate($month,$day,$year)) return true;
else return false;
}
else return false;
} function isint($str){
$str = (string)$str; $pos = 0;
$len = strlen($str);
for($i=0;$i<$len;$i++){
if($str[$i]=='0') $pos++;
else break;
}
$str = substr($str,$pos); $int = (int)$str;
if($str==(string)$int) return true;
else return false;
}