PHP Method for retrieving constellation and Zodiac signs with ID card numbers _ php instance

Source: Internet
Author: User
PHP uses the ID card number to obtain constellation and Zodiac signs. A practical PHP function The Code is as follows:


<? Php
// PHP automatically obtains the corresponding constellation function based on the ID card number
Function get_xingzuo ($ cid) {// automatically returns the corresponding Constellation Based on the ID card number
If (! IsIdCard ($ cid) return '';
$ Bir = substr ($ cid, 10, 4 );
$ Month = (int) substr ($ bir, 0, 2 );
$ 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 ";
} Else 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 <= 19 )){
$ StrValue = "Capricorn ";
}
Return $ strValue;

}
Function get_shengxiao ($ cid) {// the ID card number automatically returns the corresponding Chinese 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 = "";}
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 gender based on ID card number
If (! IsIdCard ($ cid) return '';
$ Sexint = (int) substr ($ cid, 16, 1 );

Return $ sexint % 2 === 0? Female: Male ';
}
Function isIdCard ($ number) {// check whether it is an ID card number
// Convert to uppercase, if x appears
$ Number = strtoupper ($ number );
// 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 and convert the variable type into a real number
$ B = (int) $ number {$ I };

// Extract the corresponding weighting factor
$ W = $ wi [$ I];

// Multiply the number extracted from the ID card number and the weighting factor, and accumulate
$ Sigma + = $ B * $ w;
}
// Calculates the serial number.
$ Snumber = $ sigma % 11;

// Extract the corresponding characters from the check string according to the serial number.
$ Check_number = $ ai [$ snumber];

If ($ number {17 }==$ check_number ){
Return true;
} Else {
Return false;
}
}
?>

In addition, the ID card number verification site also providesLocal ID card Query ToolAs follows:

Http://tools.php.net/bianmin/sfz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.