PHP extracts the birthday date from the ID number and determines whether a function is adult. Can be determined at the same time 15-bit and 18-bit ID card, by my pro-test, very useful, share the function code as follows:
<?PHP//use PHP to extract birthdays from your ID, including 15-and 18-bit IDsfunctionGetidcardinfo ($IDCard){ $result[' Error ']=0;//0: Unknown error, 1: ID card format error, 2: Error free $result[' Flag ']= ';//0 marked Adulthood, 1 marked minors $result[' Tdate ']= ';//birthday, format such as: 2012-11-15 if(!Eregi("^[1-9" ([0-9a-za-z]{17}|[ 0-9A-ZA-Z]{14}) $ ",$IDCard)){ $result[' Error ']=1; return $result; }Else{ if(strlen($IDCard) ==18){ $tyear=intval(substr($IDCard, 6,4)); $tmonth=intval(substr($IDCard, 10,2)); $tday=intval(substr($IDCard, 12,2)); if($tyear>Date("Y") | |$tyear< (Date("Y")-100)){ $flag=0; }ElseIf($tmonth<0| |$tmonth>12){ $flag=0; }ElseIf($tday<0| |$tday>31){ $flag=0; }Else{ $tdate=$tyear." -".$tmonth." -".$tday." 00:00:00 "; if(( Time()-Mktime(0,0,0,$tmonth,$tday,$tyear)) >18*365*24*60*60){ $flag=0; }Else{ $flag=1; } } }ElseIf(strlen($IDCard) ==15){ $tyear=intval("19".substr($IDCard, 6,2)); $tmonth=intval(substr($IDCard, 8,2)); $tday=intval(substr($IDCard, 10,2)); if($tyear>Date("Y") | |$tyear< (Date("Y")-100)){ $flag=0; }ElseIf($tmonth<0| |$tmonth>12){ $flag=0; }ElseIf($tday<0| |$tday>31){ $flag=0; }Else{ $tdate=$tyear." -".$tmonth." -".$tday." 00:00:00 "; if(( Time()-Mktime(0,0,0,$tmonth,$tday,$tyear)) >18*365*24*60*60){ $flag=0; }Else{ $flag=1; } } } } $result[' Error ']=2;//0: Unknown error, 1: ID card format error, 2: Error free $result[' Isadult ']=$flag;//0 marked Adulthood, 1 marked minors $result[' Birthday ']=$tdate;//Birthday Date return $result;}
PHP Extract the birthday date from the ID number and the function to verify whether it is a minor