Home > Article > Backend Development > PHP function to obtain the birthday in the ID card and verify whether it is an adult
This article mainly introduces the functions of php to obtain the birthday in the ID card and verify whether it is an adult. Interested friends can refer to it. I hope it will be helpful to everyone.
php A function to extract the birthday date from the ID number and determine whether you are an adult. 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; }
The usage is as follows:
The code is as follows:
getIDCardInfo('身份证号码');
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Mysql Three commonly used functions
How to get a specified column in an array in PHP (Case)
How does PHP determine the operator based on the mobile phone number (Example)
The above is the detailed content of PHP function to obtain the birthday in the ID card and verify whether it is an adult. For more information, please follow other related articles on the PHP Chinese website!