当前位置:网站首页>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;
}
边栏推荐
- Install redis
- Redis守护进程无法停止解决方案
- leetcode3、實現 strStr()
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
- Basic operations of databases and tables ----- default constraints
- leetcode3、实现 strStr()
- A glimpse of spir-v
- 【Flask】获取请求信息、重定向、错误处理
- A Cooperative Approach to Particle Swarm Optimization
- MATLB | real time opportunity constrained decision making and its application in power system
猜你喜欢
Force buckle 9 palindromes
MUX VLAN configuration
NiO related knowledge (II)
Force buckle 1020 Number of enclaves
Basic operations of databases and tables ----- primary key constraints
[ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
TrueType字体文件提取关键信息
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
Docker compose configures MySQL and realizes remote connection
随机推荐
dried food! Accelerating sparse neural network through hardware and software co design
Tensorflow customize the whole training process
使用npm发布自己开发的工具包笔记
MCU lightweight system core
干货!通过软硬件协同设计加速稀疏神经网络
Folio.ink 免费、快速、易用的图片分享工具
TrueType字体文件提取关键信息
selenium 等待方式
Redis守护进程无法停止解决方案
Yii console method call, Yii console scheduled task
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
GBase 8c数据库升级报错
Ali test Open face test
Win10 add file extension
Format code_ What does formatting code mean
Electrical data | IEEE118 (including wind and solar energy)
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Code review concerns
500 lines of code to understand the principle of mecached cache client driver
500 lines of code to understand the principle of mecached cache client driver