search
Homephp教程php手册php提取身份证号码中的生日日期以及验证是否为成年人的函数,身份证号码成年人

php提取身份证号码中的生日日期以及验证是否为成年人的函数,身份证号码成年人

php 提取身份证号码中的生日日期以及确定是否成年的一个函数。可以同时确定15位和18位的身份证,经本人亲测,非常好用,分享函数代码如下:

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

用法如下:

复制代码 代码如下:
getIDCardInfo('身份证号码');

以上代码就是小编跟大家分享的php提取身份证号码中的生日日期以及验证是否为成年人的函数,希望对大家有用。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools