Use PHP to obtain a series of clues (constellation, Zodiac, birthday, etc.) from the ID number _php instance

Source: Internet
Author: User
Tags strlen

The first example of this article for everyone to share the PHP according to the ID number, automatically obtain the corresponding constellation function, for your reference, the specific contents are as follows

<?php function 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 = "double fish Seat"; 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 &Lt;=) {$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 returns 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 = "ox";}
  if ($x = = One | | $x = = 1) {$value = "Tiger";} if ($x = = | | $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;
  The function Get_xingbie ($cid) {//automatically returns the gender if (!isidcard ($CID)) return according to the ID number;
   
  $sexint = (int) substr ($cid, 16, 1); return $sexint% 2 = 0?
' Female ': ' Male ';
  The function Isidcard ($number) {//Check whether it is an ID number//conversion to uppercase, such as the occurrence of x $number = Strtoupper ($number);
  The 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 ');
  Cyclic processing of the first 17-digit $sigma = 0; 
 
    for ($i = 0; $i < $i + +) {//extract one of the top 17 digits and convert the variable type to real $b = (int) $number {$i};
 
    Extracting the corresponding weighting factor $w = $wi [$i]; Multiplies a number and weighted factor that is extracted from the ID number and adds $sigma+ $b * $W; 
 
  ///number $snumber = $sigma% 11; 
  Extracts the corresponding characters from the checksum code string by serial number.
 
  $check _number = $ai [$snumber];
  if ($number {} = = = $check _number) {return true;
  else {return false;
 }}?>

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

function Getidcardinfo ($IDCard, $format =1) {$result [' Error ']=0;//0: Unknown error, 1: ID card format error, 2: no error $result [' Flag ']= ';//0 Mark Adult , 1 marks a minor $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 ("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 date of the birthday in the ID number and a function that determines whether it is adult . Can be determined at the same time 15-bit and 18-bit ID card, by my own test, very useful, sharing function code is as follows:

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

Usage is as follows:

Getidcardinfo (' ID number ');

The above code is a small series to share with you the PHP ID number of the date of the birthday and verify whether the function of adults, I hope to be useful.

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.