PHP _php Examples of how to obtain constellations and zodiac signs with a social security number

Source: Internet
Author: User
Copy CodeThe code is as follows:
<?php
PHP automatically obtains the corresponding constellation function according to the ID number.
function Get_xingzuo ($cid) {//According to the ID number, automatically return the corresponding constellation
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 = = && $day <= 23)) {
$strValue = "Libra";
} else if (($month = = && $day > 23) | | ($month = = && $day <= 22)) {
$strValue = "Scorpio";
} else if (($month = = && $day > 22) | | ($month = = && $day <= 21)) {
$strValue = "Sagittarius";
} else if (($month = = && $day > 21) | | ($month = = 1 && $day <= 19)) {
$strValue = "Capricorn";
}
return $strValue;

}
function Get_shengxiao ($cid) {//According to the ID number, automatically return the corresponding Zodiac
if (!isidcard ($cid)) return ';
$start = 1901;
$end = $end = (int) substr ($cid, 6,4);
$x = ($start-$end)% 12;
$value = "";
if ($x = = 1 | | $x = = -11) {$value = "mouse";}
if ($x = = 0) {$value = "Bull";}
if ($x = = | | $x = =-1) {$value = "Tiger";}
if ($x = = Ten | | $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 = "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 the ID number, automatically return gender
if (!isidcard ($cid)) return ';
$sexint = (int) substr ($cid, 16, 1);

return $sexint% 2 = = = 0? ' Female ': ' Male ';
}
function Isidcard () {//Check whether it is a social security number
Convert to uppercase, such as X
= Strtoupper ();
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 ');
Cycle through the first 17 bits sequentially
$sigma = 0;
for ($i = 0; $i < $i + +) {
Extract one of the first 17 bits and convert the variable type to real
$b = (int) {$i};

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

Multiplies a number and weighting factor extracted from the ID number and accumulates
$sigma + = $b * $W;
}
Calculate number
$snumber = $sigma% 11;

Extracts the corresponding characters from the check code string by ordinal.
$check _number = $ai [$snumber];

if ({_number} = = $check) {
return true;
} else {
return false;
}
}
?>

In addition, regarding the identification number verification This site also provides the identity card attribution to query tool as follows:

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

  • Related Article

    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.