Use PHP to get a series of clues from your ID number (constellation, Zodiac, birthday, etc.), PHP ID number _php Tutorial

Source: Internet
Author: User

Use PHP to get a series of clues from your ID number (constellation, Zodiac, birthday, etc.), PHP ID number


The first example of this article for everyone to share the PHP according to the identity card number, automatically obtain the corresponding constellation function, for your reference, the specific content is as follows

<?phpfunction Get_xingzuo ($cid) {//According to the ID number, automatically returns 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 returns the gender if (!isidcard ($cid)) return ';     $sexint = (int) substr ($cid, 16, 1); return $sexint% 2 = = = 0? ' Female ': ' Male ';}  function Isidcard ($number) {//Check whether it is a social Security number//conversion to uppercase, such as x $number = Strtoupper ($number);  Weighted 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 ');  The first 17 digits are processed sequentially $sigma = 0;      for ($i = 0; $i <; $i + +) {//extract one of the first 17 bits and convert the variable type to real $b = (int) $number {$i};     Extract the corresponding weighting factor $w = $wi [$i];   Multiply a number and weighting factor extracted from the ID number and accumulate $sigma + = $b * $W;    }//Calculate ordinal $snumber = $sigma% 11;   Extracts the corresponding characters from the check code string by ordinal. $cheCk_number = $ai [$snumber];  if ($number {+} = = $check _number) {return true;  } else {return false; }}?>

Second instance: Use PHP to extract birthdays from your ID, including 15-and 18-bit IDs:

function Getidcardinfo ($IDCard, $format =1) {$result [' Error ']=0;//0: Unknown error, 1: Identity card format error, 2: Error-free $result [' flag ']= ';//0 marked adult , 1 indicates underage $result [' tdate ']= ';//birthday, format such as: 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 ("n". 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 (0,0,0, $tmonth, $tday, $tyear)) (>18*365*24*60*60) {$flag = 0;   } else {$flag = 1; }}} $result [' Error ']=2;//0: Unknown error, 1: ID card format error, 2: no error $result [' Isadult ']= $flag;//0 marked adult, 1 marked underage $result [' Birthday ']= $tdate;//Birthday date return $ Result }

Last instance: PHP extracts the birthday date from the identity card number and determines whether a function of adulthood is . Can be determined at the same time 15-bit and 18-bit ID card, by my pro-test, very useful, share the function code as follows:

<?php//use PHP to extract birthdays from ID, including bit and bit ID card function Getidcardinfo ($IDCard) {$result [' Error ']=;//: Unknown error: ID format error: no error $result [ ' Flag ']= ';//mark Adult, Mark underage $result [' tdate ']= ';//birthday, format such as:-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: ID format error: no error $result [' Isadult ']= $flag;//marked adult, marked minor $result [' Birthday ']= $tdate;/ Birthday date return $result;}

Use the following:

Getidcardinfo (' ID card number ');

The above code is a small part of the PHP to share with you to extract the birthday date in the ID card number and verify whether it is an adult function, hope to be useful to everyone.

http://www.bkjia.com/PHPjc/1125873.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125873.html techarticle use PHP to get a series of clues from the ID number (constellation, Zodiac, birthday, etc.), PHP ID number of the first instance of this article for everyone to share the PHP according to the ID number, automatically get the corresponding ...

  • 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.