Provides various official and user-released code examples and code reference. You are welcome to exchange and learn how to place orders and enter your ID card when developing the travel website program's second generation travel CMS, we just need to use the automatic birthday extraction function. Share it now.
Compatible with 15-digit and 18-digit ID cards
In the development of tourism website program, the second generation of tourism CMS (http://www.erdaicms.com), the user orders, fill in the ID card, just to use the automatic extraction of the birthday function, now share it out.
Very easy to use, compatible with 15-digit and 18-digit ID cards
// Use php to extract the birthday from the ID card, including 15-digit and 18-digit ID cards
Function getIDCardInfo ($ IDCard ){
$ Result ['error'] = 0; // 0: Unknown error, 1: Incorrect ID card format, 2: no error
$ Result ['flag'] = ''; // 0 indicates adult, 1 indicates minor
$ Result ['tdate'] = ''; // birthday, in the format of 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 (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; // birthday date
Return $ result;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB