Home > php教程 > php手册 > 分享一个PHP从身份证号码中提取生日的函数

分享一个PHP从身份证号码中提取生日的函数

WBOY
Release: 2016-06-07 11:34:25
Original
1963 people have browsed it

在开发旅游网站程序二代旅游CMS的时候,用户下单,填写身份证的时候,刚好要用到自动提取生日的功能,现在分享出来吧
兼容15位和18位身份证
在开发旅游网站程序,二代旅游CMS(http://www.erdaicms.com)的时候,用户下单,填写身份证的时候,刚好要用到自动提取生日的功能,现在分享出来吧。
很好用,兼容15位和18位身份证//用php从身份证中提取生日,包括15位和18位身份证 <br> function getIDCardInfo($IDCard){ <br>     $result['error']=0;//0:未知错误,1:身份证格式错误,2:无错误 <br>     $result['flag']='';//0标示成年,1标示未成年 <br>     $result['tdate']='';//生日,格式如:2012-11-15 <br>     if(!eregi("^[1-9]([0-9a-zA-Z]{17}|[0-9a-zA-Z]{14})$",$IDCard)){ <br>         $result['error']=1; <br>         return $result; <br>     }else{ <br>         if(strlen($IDCard)==18){ <br>             $tyear=intval(substr($IDCard,6,4)); <br>             $tmonth=intval(substr($IDCard,10,2)); <br>             $tday=intval(substr($IDCard,12,2)); <br>             if($tyear>date("Y")||$tyear                 $flag=0; <br>             }elseif($tmonth12){ <br>                 $flag=0; <br>             }elseif($tday31){ <br>                 $flag=0; <br>             }else{ <br>                 $tdate=$tyear."-".$tmonth."-".$tday." 00:00:00"; <br>                 if((time()-mktime(0,0,0,$tmonth,$tday,$tyear))>18*365*24*60*60){ <br>                     $flag=0; <br>                 }else{ <br>                     $flag=1; <br>                 } <br>             } <br>         }elseif(strlen($IDCard)==15){ <br>             $tyear=intval("19".substr($IDCard,6,2)); <br>             $tmonth=intval(substr($IDCard,8,2)); <br>             $tday=intval(substr($IDCard,10,2)); <br>             if($tyear>date("Y")||$tyear                 $flag=0; <br>             }elseif($tmonth12){ <br>                 $flag=0; <br>             }elseif($tday31){ <br>                 $flag=0; <br>             }else{ <br>                 $tdate=$tyear."-".$tmonth."-".$tday." 00:00:00"; <br>                 if((time()-mktime(0,0,0,$tmonth,$tday,$tyear))>18*365*24*60*60){ <br>                     $flag=0; <br>                 }else{ <br>                     $flag=1; <br>                 } <br>             } <br>         } <br>     } <br>     $result['error']=2;//0:未知错误,1:身份证格式错误,2:无错误 <br>     $result['isAdult']=$flag;//0标示成年,1标示未成年 <br>     $result['birthday']=$tdate;//生日日期 <br>     return $result; <br> } 

AD:真正免费,域名+虚机+企业邮箱=0元

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template