Home  >  Article  >  Backend Development  >  PHP function to obtain the birthday in the ID card and verify whether it is an adult

PHP function to obtain the birthday in the ID card and verify whether it is an adult

墨辰丷
墨辰丷Original
2018-06-07 10:36:392030browse

This article mainly introduces the functions of php to obtain the birthday in the ID card and verify whether it is an adult. Interested friends can refer to it. I hope it will be helpful to everyone.

php A function to extract the birthday date from the ID number and determine whether you are an adult. 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:

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;
}

The usage is as follows:

The code is as follows:

getIDCardInfo('身份证号码');

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

Mysql Three commonly used functions

How to get a specified column in an array in PHP (Case)

How does PHP determine the operator based on the mobile phone number (Example)

The above is the detailed content of PHP function to obtain the birthday in the ID card and verify whether it is an adult. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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