//根据出生日期计算年龄,如果传入的出生日期为.01格式,则把.正则替换为-function countAge($birthday){$birthday=preg_replace("/\./i", '-', $birthday);$age = strtotime($birthday);if($age === false){return false;}list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));$now = strtotime("now");list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));$age = $y2 - $y1;if((int)($m2.$d2) < (int)($m1.$d1))$age -= 1;return $age;}
如果觉得《php计算根据出生日期计算年龄》对你有帮助,请点赞、收藏,并留下你的观点哦!