国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP用身份證號(hào)獲取星座和生肖的方法

2024-05-04 23:19:23
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:


<?php
// PHP根據(jù)身份證號(hào),自動(dòng)獲取對(duì)應(yīng)的星座函數(shù)
function get_xingzuo($cid) { // 根據(jù)身份證號(hào),自動(dòng)返回對(duì)應(yīng)的星座
 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 >= 20) || ($month == 2 && $day <= 18)) {
  $strValue = "水瓶座";
 } else if (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) {
  $strValue = "雙魚座";
 } else if (($month == 3 && $day > 20) || ($month == 4 && $day <= 19)) {
  $strValue = "白羊座";
 } else if (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) {
  $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 <= 22)) {
  $strValue = "獅子座";
 } else if (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) {
  $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 <= 19)) {
  $strValue = "魔羯座";
 }
 return $strValue;

}
function get_shengxiao($cid) { //根據(jù)身份證號(hào),自動(dòng)返回對(duì)應(yīng)的生肖
 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) { //根據(jù)身份證號(hào),自動(dòng)返回性別
 if (!isIdCard($cid)) return '';
 $sexint = (int)substr($cid,16,1);

 return $sexint % 2 === 0 ? '女' : '男';
}
function isIdCard($number) { // 檢查是否是身份證號(hào)
 // 轉(zhuǎn)化為大寫,如出現(xiàn)x
 $number = strtoupper($number);
 //加權(quán)因子
 $wi = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
 //校驗(yàn)碼串
 $ai = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
 //按順序循環(huán)處理前17位
 $sigma = 0;
 for ($i = 0;$i < 17;$i++) {
  //提取前17位的其中一位,并將變量類型轉(zhuǎn)為實(shí)數(shù)
  $b = (int) $number{$i};

  //提取相應(yīng)的加權(quán)因子
  $w = $wi[$i];

  //把從身份證號(hào)碼中提取的一位數(shù)字和加權(quán)因子相乘,并累加
  $sigma += $b * $w;
 }
 //計(jì)算序號(hào)
 $snumber = $sigma % 11;

 //按照序號(hào)從校驗(yàn)碼串中提取相應(yīng)的字符。
 $check_number = $ai[$snumber];

 if ($number{17} == $check_number) {
  return true;
 } else {
  return false;
 }
}
?>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴国县| 峨眉山市| 浪卡子县| 英德市| 亚东县| 奉新县| 五寨县| 浦东新区| 杨浦区| 辛集市| 集贤县| 安平县| 新安县| 尚志市| 敖汉旗| 日喀则市| 洞头县| 夹江县| 称多县| 蕉岭县| 岳普湖县| 沈丘县| 陆良县| 棋牌| 泰顺县| 象山县| 新沂市| 连南| 瓦房店市| 射阳县| 固原市| 蓝田县| 咸丰县| 高密市| 香港 | 平凉市| 浮梁县| 枣庄市| 鄢陵县| 绥宁县| 紫金县|