PHP extracts the birthday date from the ID number and determines whether a function is adult. Both 15-and 18-bit IDs can be identified at the same time.
Share the function code as follows:
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 ("n". 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: no error $result[' Isadult ']= $flag;//0 marked adult, 1 marked minor $result[' birthday ']= $tdate; /Birthday date return $result;}