// PHP 根据身份证号,自动获取对应的星座函数
function get_xingzuo($cid) { // 根据身份证号,自动返回对应的星座if (!isIdCard($cid)) return '';$bir = substr($cid,10,4);$month = (int)substr($bir,0,2);$day = (int)substr($bir,2);$strValue = '';if(($month == 1 && $day <= 21) || ($month == 2 && $day <= 19)) { $strValue = "水瓶座"; }else if(($month == 2 && $day > 20) || ($month == 3 && $day <= 20)) { $strValue = "双鱼座"; }else if (($month == 3 && $day > 20) || ($month == 4 && $day <= 20)) { $strValue = "白羊座"; }else if (($month == 4 && $day > 20) || ($month == 5 && $day <= 21)) { $strValue = "金牛座"; }else if (($month == 5 && $day > 21) || ($month == 6 && $day <= 21)) { $strValue = "双子座"; }else if (($month == 6 && $day > 21) || ($month == 7 && $day <= 22)) { $strValue = "巨蟹座"; }else if (($month == 7 && $day > 22) || ($month == 8 && $day <= 23)) { $strValue = "狮子座"; }else if (($month == 8 && $day > 23) || ($month == 9 && $day <= 23)) { $strValue = "处女座"; }else if (($month == 9 && $day > 23) || ($month == 10 && $day <= 23)) { $strValue = "天秤座";}else if (($month == 10 && $day > 23) || ($month == 11 && $day <= 22)) { $strValue = "天蝎座"; }else if (($month == 11 && $day > 22) || ($month == 12 && $day <= 21)) { $strValue = "射手座"; }else if (($month == 12 && $day > 21) || ($month == 1 && $day <= 20)) {$strValue = "魔羯座";}  return $strValue;
}
//根据身份证号,自动返回对应的生肖
function get_shengxiao($cid) {if(!isIdCard($cid)) return '';$start = 1901;$end = $end = (int)substr($cid,6,4);$x = ($start - $end) % 12;$value = "";if($x == 1 || $x == -11){$value = "鼠";}if($x == 0) {$value = "牛";} if($x == 11 || $x == -1){$value = "虎";}if($x == 10 || $x == -2){$value = "兔";}if($x == 9 || $x == -3){$value = "龙";}if($x == 8 || $x == -4){$value = "蛇";}if($x == 7 || $x == -5){$value = "马";}if($x == 6 || $x == -6){$value = "羊";}if($x == 5 || $x == -7){$value = "猴";}if($x == 4 || $x == -8){$value = "鸡";}if($x == 3 || $x == -9){$value = "狗";}if($x == 2 || $x == -10){$value = "猪";}return $value;
}
//根据身份证号,自动返回性别
function get_xingbie($cid) {if(!isIdCard($cid)) return '';$sexint = (int)substr($cid,16,1);return $sexint % 2 === 0 ? '女' : '男';
}
//检查是否是身份证号public function isIdCard($id) {$id        = strtoupper($id);$regx      = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";$arr_split = array();if (!preg_match($regx, $id)) {return false;}if (15 == strlen($id)) //检查15位{$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";@preg_match($regx, $id, $arr_split);//检查生日日期是否正确$dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];if (!strtotime($dtm_birth)) {return false;} else {return true;}} else //检查18位{$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";@preg_match($regx, $id, $arr_split);$dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];if (!strtotime($dtm_birth)) //检查生日日期是否正确{return false;} else {//检验18位身份证的校验码是否正确。//校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);$arr_ch  = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');$sign    = 0;for ($i = 0; $i < 17; $i++) {$b = (int) $id[$i];$w = $arr_int[$i];$sign += $b * $w;}$n       = $sign % 11;$val_num = $arr_ch[$n];if ($val_num != substr($id, 17, 1)) {return false;}else {return true;}}}}
# 1.从身份证中获取出生日期
$stridbirthday = substr($idno, 6, 8);//idno是身份证号 截取日期并转为时间戳
$birthday = substr(stridbirthday,0,4).'-'. substr(stridbirthday,4,2).'-'. substr(stridbirthday,6,2);
//获取性别
public function getAgeFromIdNo($idno = ''){$btime = strtotime(substr($idno, 6, 8));//idno是身份证号 截取日期并转为时间戳$byear = date('Y', $btime);$bmonth = date('m', $btime);$bday = date('d', $btime);$curYear = date('Y');$curMoth = date('m');$curDay = date('d');$age = $curYear - $byear;if ($curMoth < $bmonth || ($curMoth == $bmonth && $curDay < $bday)) {$age--;}return $age;}public function get_age($idcard){if(empty($idcard)) return null;#  获得出生年月日的时间戳$date = strtotime(substr($idcard,6,8));#  获得今日的时间戳$today = strtotime('today');#  得到两个日期相差的大体年数$diff = floor(($today-$date)/86400/365);#  strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比$age = strtotime(substr($idcard,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;return $age;}

php 验证身份证(获取年龄、性别、出生日期)相关推荐

  1. java身份证工具类(校验身份证是否合法、通过身份证获取年龄、性别、生日,将15位身份证转为18位等)

    一.简介 因为工作需要经常用到身份证做一些相关操作,于是通过查阅资料总结出一些常用的工具方法,包括校验身份证是否合法.通过身份证获取年龄.通过身份证获取性别.通过身份证获取户籍地址.通过身份证获取生日 ...

  2. 通过身份证获取年龄和性别

    需要引入commons-lang包 package com.zjx.util;import org.apache.commons.lang.StringUtils;import java.text.S ...

  3. orcal根据身份证获取年龄

    --根据身份证获取年龄 select   floor(months_between(SYSDATE, to_date(substr2(a.identifynumber, 7, 8), 'yyyy-mm ...

  4. JAVA 根据身份证获取年龄

    JAVA 根据身份证获取年龄 这里我选用了一条19900407的, 今天的日期是2021/04/10 显示的年龄为31岁. private static int getAge(String idCar ...

  5. sql根据身份证获取年龄、性别、出生日期等信息

    #属性nl为年龄;sfzh为身份证号;xb 为性别;csrq 为出生日期 #根据身份证计算年龄并修改 update kw_test set nl= (substring(now(),1,4)-subs ...

  6. 【Flutter】Dart 校验身份证号合法性,根据身份证号获取年龄性别

    js版或OC.Java版的都容易找到,Dart版的比较少,mark一下吧. // 校验身份证合法性 bool verifyCardId(String cardId) {const Map city = ...

  7. 通过身份证获取:性别、年龄、星座、生肖

    性别 /*** 根据身份证号判断性别 奇数代表男 偶数代表女* @param idNumber* @return*/ public static String gender(String idNumb ...

  8. js 验证身份证号,根据身份证获取出生年月/性别

    用到的input <input id="idCard" name="idCard" class="form-control" type ...

  9. 【通用方法】身份证号校验、获取年龄性别生日(兼容一代二代身份证)

    二代身份证正则表达式 /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2])) ...

  10. vue element-ui 通过身份证获取年龄,出生日期

    页面代码: <el-dialog :title="title" :visible.sync="open" width="700px" ...

最新文章

  1. Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type
  2. 【RxSwift】flatMapLatest、 Error事件中断序列
  3. 发送经纬度坐标给指定手机
  4. git push 代码报错 Pushing to Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
  5. 函的红头文件格式制作_Excel实现批量制作年会邀请函,这个方法,你一定不能错过...
  6. win7 ghost 纯净版最新系统下载
  7. 5个Vue.js项目的令人敬畏的模板
  8. jdbc java_Java中使用JDBC
  9. 1818国民经济核算
  10. boost::shared_mutex
  11. 怎么样自己动手写OS
  12. (70)FPGA资源优化有哪些方法?手写FIFO代替BRAM
  13. iPhone新机或全部采用OLED屏:日本JDI股价应声下跌
  14. CentOS7添加Nginx为系统服务
  15. vue-router的beforeEach的使用?
  16. 【信息系统项目管理师】第7章-项目成本管理 知识点详细整理
  17. python SVG图片转PNG
  18. js监听中文拼音输入开始输入和输入完成的事件,用input事件用拼音输入法的大坑,由这两个事件来解决
  19. 重置网络命令win7
  20. 【Nginx服务优化与防盗链】

热门文章

  1. 原生js实现轮播图-滑入滑出效果
  2. LeetCode:342(Python)—— 4 的幂(简单)
  3. i.MX6ULL终结者mfgtool烧写镜像
  4. vuex的辅助函数:mapState和mapGetters
  5. 【笔记整理】vuex介绍和原理以及mapState与mapGetters、mapActions与mapMutations
  6. Python缩进规则(包含快捷键)
  7. 聊聊单点登录(SSO)中的CAS认证
  8. COI实验室技能:常见的图像增强算法(含MATLAB代码)
  9. 联想(Lenovo)小新锐7000 一系列问题
  10. 自由幻想系统不能提供服务器,自由幻想手游为什么不能转区 人物转区注意事项...