PHP-身份证号识别年龄

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QWQP_7/article/details/82014386
/*
* 根据身份证号码获取年龄
* inupt   $code = 完整的身份证号
* return  $age : 年龄
*/
function ageVerification($code){
    $age_time = strtotime(substr($code, 6, 8));
    if($age_time === false){
        return false;
    }
    list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age_time)); 

    $now_time = strtotime("now");

    list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now_time));
    $age = $y2 - $y1;
    if((int)($m2.$d2) < (int)($m1.$d1)){
        $age -= 1;
    }
    return $age; 
}

猜你喜欢

转载自blog.csdn.net/QWQP_7/article/details/82014386