Use php to get a series of clues (constellation, Zodiac, birthday, etc.) from the ID card number, php ID card number
The first example of this article is to share with you that PHP automatically obtains the corresponding constellation functions based on the ID card number for your reference. The specific content is as follows:
<? Phpfunction get_xingzuo ($ cid) {// automatically returns the corresponding constellation if (! IsIdCard ($ cid) return ''; $ bir = substr ($ cid,); $ month = (int) substr ($ bir ); $ day = (int) substr ($ bir, 2); $ strValue = ''; if ($ month = 1 & $ day> = 20) | ($ month = 2 & $ day <= 18) {$ strValue = "Aquarius ";} else if ($ month = 2 & $ day> = 19) | ($ month = 3 & $ day <= 20 )) {$ strValue = "Pisces";} else if ($ month = 3 & $ day> 20) | ($ month = 4 & $ day <= 19) {$ strValue = "Aries";} el Se if ($ month = 4 & $ day> = 20) | ($ month = 5 & $ day <= 20 )) {$ strValue = "Taurus";} else if ($ month = 5 & $ day> = 21) | ($ month = 6 & $ day <= 21) {$ strValue = "Gemini ";} else if ($ month = 6 & $ day> 21) | ($ month = 7 & $ day <= 22 )) {$ strValue = "cancer";} else if ($ month = 7 & $ day> 22) | ($ month = 8 & $ day <= 22) {$ strValue = "Leo ";} else if ($ month = 8 & $ day> = 23) | ($ Month = 9 & $ day <= 22) {$ strValue = "Virgo ";} else if ($ month = 9 & $ day> = 23) | ($ month = 10 & $ day <= 23 )) {$ strValue = "Libra";} else if ($ month = 10 & $ day> 23) | ($ month = 11 & $ day <= 22) {$ strValue = "scorpio ";} else if ($ month = 11 & $ day> 22) | ($ month = 12 & $ day <= 21 )) {$ strValue = "Sagittarius";} else if ($ month = 12 & $ day> 21) | ($ month = 1 & $ day <= 1 9) {$ strValue = "Capricorn";} return $ strValue;} function get_shengxiao ($ cid) {// automatically returns the corresponding Zodiac if (! IsIdCard ($ cid) return ''; $ start = 1901; $ end = (int) substr ($ cid, 6, 4 ); $ x = ($ start-$ end) % 12; $ value = ""; if ($ x = 1 | $ x =-11) {$ value = "rat";} if ($ x = 0) {$ value = "Ox ";} if ($ x = 11 | $ x =-1) {$ value = "tiger ";} if ($ x = 10 | $ x =-2) {$ value = "rabbit ";} if ($ x = 9 | $ x =-3) {$ value = "dragon ";} if ($ x = 8 | $ x =-4) {$ value = "snake ";} if ($ x = 7 | $ x =-5) {$ value = "horse";} if ($ X = 6 | $ x =-6) {$ value = "goat";} if ($ x = 5 | $ x =-7) {$ value = "monkey";} if ($ x = 4 | $ x =-8) {$ value = "chicken ";} if ($ x = 3 | $ x =-9) {$ value = "dog ";} if ($ x = 2 | $ x =-10) {$ value = "";} return $ value;} function get_xingbie ($ cid) {// automatically returns the gender if (! IsIdCard ($ cid) return ''; $ sexint = (int) substr ($ cid, 16,1); return $ sexint % 2 = 0? Female: male;} function isIdCard ($ number) {// check whether the ID card number is in uppercase. // If x $ number = strtoupper ($ number) is displayed ); // weighting factor $ wi = array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // check code string $ ai = array ('1', '0', 'x', '9', '8', '7 ', '6', '5', '4', '3', '2'); // process the first 17 digits in a sequential loop $ sigma = 0; for ($ I = 0; $ I <17; $ I ++) {// extract one of the first 17 digits, convert the variable type to the real number $ B = (int) $ number {$ I}; // extract the corresponding weighting factor $ w = $ wi [$ I]; // multiply the number extracted from the ID card number by the weighting factor, And accumulate $ sigma + = $ B * $ w;} // calculates the serial number $ snumber = $ sigma % 11; // extracts the corresponding characters from the checkcode string according to the serial number. $ Check_number = $ ai [$ snumber]; if ($ number {17 }==$ check_number) {return true;} else {return false ;}}?>
Second Instance: UsePhp extracts the birthday from the ID card, including 15-digit and 18-digit ID cards:
Function getIDCardInfo ($ IDCard, $ format = 1) {$ 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, format: 2012-11-15 if (! Preg_match ("/^ (\ d {15 }$ | ^ \ d {18 }$ | ^ \ d {17} (\ d | X | x) $ /", $ 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);} 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 {if ($ format) {$ tdate = $ tyear. "-". $ tmonth. "-". $ tday;} else {$ tdate = $ tmonth. "-". $ tday;} 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 ;}
Last Instance: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 useful after my own test. The function code is as follows:
<? Php // Use php to extract the birthday from the ID card, including the bit and bit ID card function getIDCardInfo ($ IDCard) {$ result ['error'] =; // unknown error ,: incorrect ID card format: no error $ result ['flag'] = ''; // indicates the adult, indicating the minor $ result ['tdate'] =''; // birthday, format: -- 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'] =; // unknown error: Incorrect ID card format ,: no error $ result ['isadresult'] = $ flag; // indicates the adult, indicating the minor $ result ['birthday'] = $ tdate; // return $ result on the birthday date ;}
The usage is as follows:
GetIDCardInfo ('Id card number ');
The above code is a php function used to extract the birthday date in the ID card number and verify whether it is an adult.