Home > Backend Development > PHP Tutorial > PHP function to extract the birthday date from the ID card number and verify whether it is an adult, ID card number is an adult_PHP tutorial

PHP function to extract the birthday date from the ID card number and verify whether it is an adult, ID card number is an adult_PHP tutorial

WBOY
Release: 2016-07-12 09:08:01
Original
1327 people have browsed it

php function to extract the birthday date from the ID card number and verify whether it is an adult, ID card number for adults

php extract the birthday date from the ID card number and determine whether it is an adult A function of adulthood. It can determine 15-digit and 18-digit ID cards at the same time. After personal testing, it is very easy to use. The shared function code is as follows:

<&#63;php
//用php从身份证中提取生日,包括位和位身份证
function getIDCardInfo($IDCard){
  $result['error']=;//:未知错误,:身份证格式错误,:无错误
  $result['flag']='';//标示成年,标示未成年
  $result['tdate']='';//生日,格式如:--
  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']=;//:未知错误,:身份证格式错误,:无错误
  $result['isAdult']=$flag;//标示成年,标示未成年
  $result['birthday']=$tdate;//生日日期
  return $result;
}
Copy after login

Usage is as follows:

Copy code The code is as follows:
getIDCardInfo('ID card number');

The above code is the php function that the editor shared with you to extract the birthday date from the ID card number and verify whether it is an adult. I hope it will be useful to everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058165.htmlTechArticlephp function to extract the birthday date in the ID number and verify whether it is an adult, ID number adult php Extract the birthday date from the ID number and determine whether you are an adult...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template