php日期合法性,检查年月日形式的日期合法性

[code]

/*

这个函数可以用来检查年月日形式的日期合法性,您只要稍作修改便可以检查其它形式的日期合法性.

功能:日期合法性检查

返回: true(合法)/false(不合法)

参数:$ymd 年月日形式的日期

$sep 年月日之间的分隔符,默认为-

*/

function datecheck($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;

}

www.444p.com

// [ php/inc/isint.php ] cvs 1.2

function isint($str){

$str = (string)$str; 本文来自 www.444p.com

$pos = 0;

$len = strlen($str);

for($i=0;$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(

'2000-4-11' => '-',

'1900-2-1' => '-',

'2001-03-01' => '-',

'abaf' => '-',

'20.03.05' => '.'

);

while(list($date,$sep)=each($dates)){

if(datecheck($date,$sep)) echo $date.' 是合法日期
';

else echo $date.' 不是合法日期
';

}

//

?>[/code]

98505370e6c9435d64fee89bd10e3e53.png php学习之家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值