php获取身份证号码的年龄函数
php获取身份证号码年龄,php判断身份证号码年龄,可以根据需求,自行添加身份证格式的判断
函数
/** * [getAgeByID 判断身份证号码年龄] * @param [string] $id [身份证号码] * @return [int] [年龄] * @author [建百站www.jianbaizhan.com] */ function getAgeByI($id){ //过了这年的生日才算多了1周岁 if(empty($id)) return ''; $date=strtotime(substr($id,6,8)); //获得出生年月日的时间戳 $today=strtotime('today'); //获得今日的时间戳 $diff=floor(($today-$date)/86400/365); //得到两个日期相差的大体年数 //strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比 $age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff; return $age; }
使用方法
echo getAgeByID('112233198001012233');
本文作者: Liaodeity
本文链接: https://www.jianbaizhan.com/article/271
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!