当前位置:网站首页>Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
2022-07-06 01:45:00 【Geek iron Han】
Here are some Encapsulated method .
/** * Whether the verification of ID card is legal * * @param string $idcard Complete body * Certificate No */
function checkIdCard($idcard = '')
{
// Can only be 18 position
if (strlen($idcard) != 18) {
return false;
}
// Take out the body code
$idcard_base = substr($idcard, 0, 17);
// Take out the check code
$verify_code = substr($idcard, 17, 1);
// Weighting factors
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
// Check code corresponding value
$verify_code_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
// According to the former 17 Bit calculation check code
$total = 0;
for ($i = 0; $i < 17; $i++) {
$total += substr($idcard_base, $i, 1) * $factor[$i];
}
// modulus
$mod = $total % 11;
// Comparison check code
if ($verify_code == $verify_code_list[$mod]) {
// If the age calculation fails , Then the judgment is The ID number is incorrect.
if (ageVerification($idcard)) {
return true;
}
}
return false;
}
/** * Get birthday according to ID number * inupt $code = Complete ID number * @return string Y-m-d */
function getBirthday($code = '')
{
$age_time = strtotime(substr($code, 6, 8));
if ($age_time === false) {
return false;
}
return date("Y-m-d", $age_time);
}
/** * Get the age according to the ID number * inupt $code = Complete ID number * @return $age : Age Three figures Such as 023 */
function ageVerification($code = '')
{
$age_time = strtotime(substr($code, 6, 8));
if ($age_time === false) {
return false;
}
list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age_time));
$now_time = strtotime("now");
list($y2, $m2, $d2) = explode("-", date("Y-m-d", $now_time));
$age = $y2 - $y1;
if ((int)($m2 . $d2) < (int)($m1 . $d1)) {
$age -= 1;
}
return $age;
}
/** * Obtain gender according to ID card 1 male 2 Woman */
function getSex($cid = ''): int
{
// Return to gender according to ID number
if (!checkIdCard($cid)) {
return 0;
}
$sexint = (int) substr($cid, 16, 1);
return 0 === $sexint % 2 ? 2 : 1;
}
/** * According to identity * Certificate No , Automatically return to the corresponding constellation */
function getXingZuo($cid = '')
{
// According to ID number , Automatically return to the corresponding constellation
if (!checkIdCard($cid)) {
return 0;
}
$bir = substr($cid, 10, 4);
$month = (int) substr($bir, 0, 2);
$day = (int) substr($bir, 2);
$strValue = '';
if ((1 == $month && $day <= 21) || (2 == $month && $day <= 19)) {
$strValue = 0; // Aquarius:
} elseif ((2 == $month && $day > 20) || (3 == $month && $day <= 20)) {
$strValue = 1; // Pisces
} elseif ((3 == $month && $day > 20) || (4 == $month && $day <= 20)) {
$strValue = 2; // Aries
} elseif ((4 == $month && $day > 20) || (5 == $month && $day <= 21)) {
$strValue = 3; // Taurus
} elseif ((5 == $month && $day > 21) || (6 == $month && $day <= 21)) {
$strValue = 4; // Gemini
} elseif ((6 == $month && $day > 21) || (7 == $month && $day <= 22)) {
$strValue = 5; // Cancer
} elseif ((7 == $month && $day > 22) || (8 == $month && $day <= 23)) {
$strValue = 6; // Leo
} elseif ((8 == $month && $day > 23) || (9 == $month && $day <= 23)) {
$strValue = 7; // Virgo
} elseif ((9 == $month && $day > 23) || (10 == $month && $day <= 23)) {
$strValue = 8; // libra
} elseif ((10 == $month && $day > 23) || (11 == $month && $day <= 22)) {
$strValue = 9; // scorpio
} elseif ((11 == $month && $day > 22) || (12 == $month && $day <= 21)) {
$strValue = 10; // Sagittarius
} elseif ((12 == $month && $day > 21) || (1 == $month && $day <= 20)) {
$strValue = 11; // Capricorn
}
return $strValue;
}
/** * Return the corresponding Zodiac according to the ID number. */
function getSh
engXiao($cid = ''): int
{
if (!checkIdCard($cid)) {
return 0;
}
$start = 1901;
$end = $end = (int) substr($cid, 6, 4);
$x = ($start - $end) % 12;
$value = '';
if (1 == $x || -11 == $x) {
$value = 0; // rat
}
if (0 == $x) {
$value = 1; // cattle
}
if (11 == $x || -1 == $x) {
$value = 2; // The tiger
}
if (10 == $x || -2 == $x) {
$value = 3; // rabbit
}
if (9 == $x || -3 == $x) {
$value = 4; // dragon
}
if (8 == $x || -4 == $x) {
$value = 5; // The snake
}
if (7 == $x || -5 == $x) {
$value = 6; // Horse
}
if (6 == $x || -6 == $x) {
$value = 7; // sheep
}
if (5 == $x || -7 == $x) {
$value = 8; // Monkey
}
if (4 == $x || -8 == $x) {
$value = 9; // chicken
}
if (3 == $x || -9 == $x) {
$value = 10; // Dog
}
if (2 == $x || -10 == $x) {
$value = 11; // The pig
}
return $value;
}
边栏推荐
- 【Flask】获取请求信息、重定向、错误处理
- 2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
- Sword finger offer 38 Arrangement of strings
- 01. Go language introduction
- LeetCode 322. Change exchange (dynamic planning)
- Ali test Open face test
- Leetcode3. Implement strstr()
- NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
- 一图看懂!为什么学校教了你Coding但还是不会的原因...
- Dynamics 365 开发协作最佳实践思考
猜你喜欢

selenium 等待方式

Basic operations of databases and tables ----- default constraints

Redis-字符串类型

NiO related knowledge (II)
![[solved] how to generate a beautiful static document description page](/img/c1/6ad935c1906208d81facb16390448e.png)
[solved] how to generate a beautiful static document description page

Basic operations of databases and tables ----- primary key constraints

Maya hollowed out modeling

一图看懂!为什么学校教了你Coding但还是不会的原因...

Redis list

【SSRF-01】服务器端请求伪造漏洞原理及利用实例
随机推荐
Force buckle 9 palindromes
ClickOnce 不支持请求执行级别“requireAdministrator”
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Basic operations of databases and tables ----- non empty constraints
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
Code Review关注点
Initialize MySQL database when docker container starts
晶振是如何起振的?
【网络攻防实训习题】
使用npm发布自己开发的工具包笔记
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
Poj2315 football games
Basic operations of databases and tables ----- primary key constraints
Huawei converged VLAN principle and configuration
selenium 等待方式
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Competition question 2022-6-26
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
Paddle framework: paddlenlp overview [propeller natural language processing development library]
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail