Php extracts the birthday date from the ID card number and verifies whether it is a minor.
Php extracts the birthday date from the ID card number and determines whether it is an adult. You can determine the ID card of 15 and 18 digits at the same time. it is very easy to use after my own test. the Function code is 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 (365, 0, $ tmonth, $ tday, $ tyear)> 18*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 (365, 0, $ tmonth, $ tday, $ tyear)> 18*24*60*60) {$ flag = 0 ;}else {$ flag = 1 ;}}$ result ['error'] = 2; // 0: Unknown error, 1: incorrect ID card format; 2: no error $ result ['isadresult'] = $ flag; // 0 indicates adult, 1 indicates minor $ result ['birthday'] = $ tdate; // return $ result ;}