$sex = substr($idcard, (strlen($idcard)==18 ? -2 : -1), 1) % 2 ? '1' : '2'; //18位身份证取性别,倒数第二位奇数是男,偶数是女;
$birthday = strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8); //取身份证年月日;
$birthdays = strtotime(strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8)); //身份证年月日转换成时间戳
$today = strtotime('today');                             //取当天日期;
$diff = floor(($today-$birthdays)/86400/365);                             //用时间戳相减算出年龄;
$age = strtotime(substr($idcard,6,8).'+'.$diff.'years')>$today?($diff+1):$diff;             //取出年龄值;
posted on 2018-11-05 18:06  kingboy_xin  阅读(1778)  评论(0编辑  收藏  举报