php extract the birthday date from the ID card number and determine whether it is an adult A function of adulthood. It can determine 15-digit and 18-digit ID cards at the same time. After personal testing, it is very easy to use. The shared function code is as follows:
<?php //用php从身份证中提取生日,包括位和位身份证 function getIDCardInfo($IDCard){ $result['error']=;//:未知错误,:身份证格式错误,:无错误 $result['flag']='';//标示成年,标示未成年 $result['tdate']='';//生日,格式如:-- if(!eregi("^[-]([-a-zA-Z]{}|[-a-zA-Z]{})$",$IDCard)){ $result['error']=; return $result; }else{ if(strlen($IDCard)==){ $tyear=intval(substr($IDCard,,)); $tmonth=intval(substr($IDCard,,)); $tday=intval(substr($IDCard,,)); if($tyear>date("Y")||$tyear<(date("Y")-)){ $flag=; }elseif($tmonth<||$tmonth>){ $flag=; }elseif($tday<||$tday>){ $flag=; }else{ $tdate=$tyear."-".$tmonth."-".$tday." ::"; if((time()-mktime(,,,$tmonth,$tday,$tyear))>****){ $flag=; }else{ $flag=; } } }elseif(strlen($IDCard)==){ $tyear=intval("".substr($IDCard,,)); $tmonth=intval(substr($IDCard,,)); $tday=intval(substr($IDCard,,)); if($tyear>date("Y")||$tyear<(date("Y")-)){ $flag=; }elseif($tmonth<||$tmonth>){ $flag=; }elseif($tday<||$tday>){ $flag=; }else{ $tdate=$tyear."-".$tmonth."-".$tday." ::"; if((time()-mktime(,,,$tmonth,$tday,$tyear))>****){ $flag=; }else{ $flag=; } } } } $result['error']=;//:未知错误,:身份证格式错误,:无错误 $result['isAdult']=$flag;//标示成年,标示未成年 $result['birthday']=$tdate;//生日日期 return $result; }
Usage is as follows:
Copy code The code is as follows:
getIDCardInfo('ID card number');
The above code is the php function that the editor shared with you to extract the birthday date from the ID card number and verify whether it is an adult. I hope it will be useful to everyone.