PHP extracts the birthday date in the ID number and verifies if it is an adult _php instance of a function

Source: Internet
Author: User

PHP extracts the birthday date in the ID number and a function to determine 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 underage $result [' Birthday '
]= $tdate;//Birthday date return $result; }

Usage is as follows:

Copy Code code 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.