Home  >  Article  >  Backend Development  >  How to get the zodiac sign and zodiac sign using ID number in PHP_PHP Tutorial

How to get the zodiac sign and zodiac sign using ID number in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:32820browse

Copy code The code is as follows:

// PHP automatically obtains the corresponding constellation function based on the ID number
function get_xingzuo($cid) { // Automatically return the corresponding constellation according to the ID 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) { //According to the ID number, automatically return the corresponding zodiac sign
if (!isIdCard($cid)) return '';
$start = 1901;
$end = $end = (int)substr($cid,6,4);
$x = ($start - $end) % 12;
$value = "";
if ( $x == 1 || $x == -11) {$value = "rat";}
if ($x == 0) { $value = "cow";}
if ($x == 11 || $x == -1) {$value = "Tiger";}
if ($x == 10 || $x == -2) {$value = "Rabbit";}
if ($x == 9 || $x == -3) {$value = "龙";}
if ($x == 8 || $x == -4) {$value = "snake";}
if ($x == 7 || $x == -5) {$value = "horse";}
if ($x == 6 || $x == - 6) {$value = "Sheep";}
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 = "pig";}
return $value;
}
function get_xingbie($cid) { //According to ID number , automatically return gender
if (!isIdCard($cid)) return '';
$sexint = (int)substr($cid,16,1);

return $sexint % 2 === 0 ? 'Female' : 'Male';
}
function isIdCard($number) { // Check if it is an ID 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');
//Loop through the first 17 digits in order
$sigma = 0;
for ($i = 0 ;$i < 17;$i++) {
//Extract one of the first 17 digits and convert the variable type to a real number
$b = (int) $number{$i};

//Extract the corresponding weighting factor
$w = $wi[$i];

//Multiply the one digit extracted from the ID number and the weighting factor, and Accumulation
$sigma += $b * $w;
}
//Calculate the serial number
$snumber = $sigma % 11;

//According to the serial number from the check code Extract the corresponding characters from the string.
$check_number = $ai[$snumber];

if ($number{17} == $check_number) {
return true;
} else {
return false;
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825068.htmlTechArticleCopy the code as follows: ?php // PHP automatically obtains the corresponding constellation function function get_xingzuo( based on the ID number $cid) { // Based on the ID number, automatically return the corresponding constellation if (!i...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn