PHP Extract the birthday date from the ID number and the function to verify whether it is a minor

Source: Internet
Author: User
PHP extracts the birthday date from the ID number and determines whether a function is adult.

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:

Use PHP to extract birthdays from your ID, including 15-and 18-bit IDs
function Getidcardinfo ($IDCard) {
$result [' Error ']=0;//0: Unknown error, 1: ID card format error, 2: Error-free
$result [' flag ']= ';//0 marked adulthood, 1 marked minors
$result [' tdate ']= ';//Birthday, Format: 2012-11-15
if (!eregi ("^[1-9") ([0-9a-za-z]{17}|[ 0-9A-ZA-Z]{14}) ($ ", $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));
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{
$tdate = $tyear. " -". $tmonth." -". $tday." 00:00:00 ";
if (Time ()-mktime (0,0,0, $tmonth, $tday, $tyear)) >18*365*24*60*60) {
$flag = 0;
}else{
$flag = 1;
}
}
}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{
$tdate = $tyear. " -". $tmonth." -". $tday." 00:00:00 ";
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: Error-free
$result [' Isadult ']= $flag;//0 marked adult, 1 marked minors
$result [' Birthday ']= $tdate;//Birthday Date
return $result;

}

Use the following:

Getidcardinfo (' ID card number ');
  • 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.