PHP通过身份证号码获取性别、出生日期、年龄等信息

您所在的位置:网站首页 根据出生日期提取出生年月 PHP通过身份证号码获取性别、出生日期、年龄等信息

PHP通过身份证号码获取性别、出生日期、年龄等信息

2024-07-01 13:55| 来源: 网络整理| 查看: 265

常用的php用身份证号码计算年龄、计算时间戳等方法! //18位身份证取性别,倒数第二位奇数是男,偶数是女; s e x = s u b s t r ( sex = substr( sex=substr(idcard, (strlen($idcard)==18 ? -2 : -1), 1) % 2 ? ‘1’ : ‘2’; //取身份证年月日; b i r t h d a y = s t r l e n ( birthday = strlen( birthday=strlen(idcard)==15 ? (‘19’ . substr( i d c a r d , 6 , 6 ) ) : s u b s t r ( idcard, 6, 6)) : substr( idcard,6,6)):substr(idcard, 6, 8); //身份证年月日转换成时间戳 b i r t h d a y s = s t r t o t i m e ( s t r l e n ( birthdays = strtotime(strlen( birthdays=strtotime(strlen(idcard)==15 ? (‘19’ . substr( i d c a r d , 6 , 6 ) ) : s u b s t r ( idcard, 6, 6)) : substr( idcard,6,6)):substr(idcard, 6, 8)); //取当天日期; $today = strtotime(‘today’); //用时间戳相减算出年龄;                             d i f f = f l o o r ( ( diff = floor(( diff=floor((today-$birthdays)/86400/365);     //取出年龄值;                         a g e = s t r t o t i m e ( s u b s t r ( age = strtotime(substr( age=strtotime(substr(idcard,6,8).’+’. d i f f . ′ y e a r s ′ ) > diff.'years')> diff.′years′)>today?( d i f f + 1 ) : diff+1): diff+1):diff;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3