当前位置:网站首页>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;
}
边栏推荐
- Ali test Open face test
- [Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
- [flask] official tutorial -part3: blog blueprint, project installability
- Basic operations of databases and tables ----- default constraints
- A picture to understand! Why did the school teach you coding but still not
- Basic operations of database and table ----- set the fields of the table to be automatically added
- 【已解决】如何生成漂亮的静态文档说明页
- 干货!通过软硬件协同设计加速稀疏神经网络
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- [the most complete in the whole network] |mysql explain full interpretation
猜你喜欢
A Cooperative Approach to Particle Swarm Optimization
Numpy array index slice
Leetcode skimming questions_ Sum of squares
Redis-字符串类型
Basic operations of databases and tables ----- unique constraints
【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化
[flask] official tutorial -part3: blog blueprint, project installability
Extracting key information from TrueType font files
Yii console method call, Yii console scheduled task
2022 PMP project management examination agile knowledge points (8)
随机推荐
Sword finger offer 12 Path in matrix
MUX VLAN configuration
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
2022年PMP项目管理考试敏捷知识点(8)
A picture to understand! Why did the school teach you coding but still not
Basic operations of databases and tables ----- unique constraints
TrueType字体文件提取关键信息
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
[flask] official tutorial -part1: project layout, application settings, definition and database access
Leetcode1961. Check whether the string is an array prefix
Redis-列表
ClickOnce does not support request execution level 'requireAdministrator'
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
A glimpse of spir-v
[flask] response, session and message flashing
Basic process and testing idea of interface automation
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
Leetcode skimming questions_ Invert vowels in a string
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
2022 PMP project management examination agile knowledge points (8)