//用php从身份证中提取生日,包括15位和18位身份证 |
02 | function getIDCardInfo( $IDCard , $format =1){ |
03 | $result [ 'error' ]=0; //0:未知错误,1:身份证格式错误,2:无错误 |
04 | $result [ 'flag' ]= '' ; //0标示成年,1标示未成年 |
05 | $result [ 'tdate' ]= '' ; //生日,格式如:2012-11-15 |
06 | if (!preg_match( "/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/" , $IDCard )){ |
07 | $result [ 'error' ]=1; |
08 | return $result ; |
09 | } else { |
10 | if ( strlen ( $IDCard )==18) |
11 | { |
12 | $tyear = intval ( substr ( $IDCard ,6,4)); |
13 | $tmonth = intval ( substr ( $IDCard ,10,2)); |
14 | $tday = intval ( substr ( $IDCard ,12,2)); |
15 | } |
16 | elseif ( strlen ( $IDCard )==15) |
17 | { |
18 | $tyear = intval ( "19" . substr ( $IDCard ,6,2)); |
19 | $tmonth = intval ( substr ( $IDCard ,8,2)); |
20 | $tday = intval ( substr ( $IDCard ,10,2)); |
21 | } |
22 | |
23 | if ( $tyear > date ( "Y" )|| $tyear <( date ( "Y" )-100)) |
24 | { |
25 | $flag =0; |
26 | } |
27 | elseif ( $tmonth <0|| $tmonth >12) |
28 | { |
29 | $flag =0; |
30 | } |
31 | elseif ( $tday <0|| $tday >31) |
32 | { |
33 | $flag =0; |
34 | } else |
35 | { |
36 | if ( $format ) |
37 | { |
38 | $tdate = $tyear . "-" . $tmonth . "-" . $tday ; |
39 | } |
40 | else |
41 | { |
42 | $tdate = $tmonth . "-" . $tday ; |
43 | } |
44 | |
45 | if ((time()- mktime (0,0,0, $tmonth , $tday , $tyear ))>18*365*24*60*60) |
46 | { |
47 | $flag =0; |
48 | } |
49 | else |
50 | { |
51 | $flag =1; |
52 | } |
53 | } |
54 | } |
55 | $result [ 'error' ]=2; //0:未知错误,1:身份证格式错误,2:无错误 |
56 | $result [ 'isAdult' ]= $flag ; //0标示成年,1标示未成年 |
57 | $result [ 'birthday' ]= $tdate ; //生日日期 |
58 | return $result ; |
59 | } |
文章来源:北大青鸟学校开发小组
本文发布于:2024-01-30 13:00:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170659080720178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |