onecoolboy
新手上路

UID 81708
精华
0
积分 31
帖子 14
金钱 31 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-10-17
状态 离线
|
[广告]: q
m
is_int函数具体运用问题!
<?
function a($ymd,$sep='-'){
$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;
}
//测试
$dates = array(
'002000-4-11' => '-',
'1900-2-1' => '-',
'2001-03-01' => '-',
'abaf' => '-',
'20.03.05' => '.' ,
"2000/18/12" => "/" ,
"2000 12 12" => " "
);
while(list($date,$sep)=each($dates)){
if(a($date,$sep)) echo $date.' 是合法日期<br/>';
else echo $date.' 不是合法日期<br/>';
}
//
?>
把自定义isint函数替换为is_int函数后,显示效果就不一样了,我也不知道什么原因,大家来看看!
我想是不是
is_int函数是判断是否为整数类型,我上面代码中把句子中单词拆分后是以字符串类型保存,所以用is_int函数判断是无效的!
对不?
|
|