当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Redis-字符串类型
抓包整理外篇——————状态栏[ 四]
Extracting key information from TrueType font files
Initialize MySQL database when docker container starts
[flask] official tutorial -part1: project layout, application settings, definition and database access
Electrical data | IEEE118 (including wind and solar energy)
Kubernetes stateless application expansion and contraction capacity
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
leetcode刷题_平方数之和
Leetcode skimming questions_ Verify palindrome string II
随机推荐
Extracting key information from TrueType font files
Yii console method call, Yii console scheduled task
dried food! Accelerating sparse neural network through hardware and software co design
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
剑指 Offer 12. 矩阵中的路径
Folio.ink 免费、快速、易用的图片分享工具
500 lines of code to understand the principle of mecached cache client driver
Ali test Open face test
2022年PMP项目管理考试敏捷知识点(8)
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
A Cooperative Approach to Particle Swarm Optimization
Win10 add file extension
Open source | Ctrip ticket BDD UI testing framework flybirds
Flutter Doctor:Xcode 安装不完整
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
Redis-Key的操作
【网络攻防实训习题】
竞价推广流程
Redis string type