Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP judge the ID number?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to judge the ID card number of PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

ID card number

/ * determine whether the parameter string is the Chinese ID card number * @ param $id string or number to be judged * @ return mixed false or array [content array boolean is true] * / function is_citizen_id ($id) {/ / length validation 18-bit ID card X is uppercase $id = strtoupper ($id) If (! (preg_match ('/ ^\ d {17} (\ d | X) $/', $id) | | preg_match ('/ ^\ d {15} $/', $id) {return false;} / / 15-digit old numbers are converted to 18 digits and converted into strings $Wi = array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1) $Ai = array ('1th,' 0th, 'Xray,' 94th, '8th,' 7th, '6th,' 5th, '4th,' 3th,'2'); $cardNoSum = 0; if (strlen ($id) = = 16) {$id = substr (0,6). '19'.substr (6,9); for ($I = 0; $I

< 17; $i++) { $cardNoSum += substr($id,$i,1) * $Wi[$i]; } $seq = $cardNoSum % 11; $id = $id.$Ai[$seq]; } //效验18位身份证最后一位字符的合法性 $cardNoSum = 0; $id17 = substr($id,0,17); $lastString = substr($id,17,1); for($i = 0; $i < 17; $i++) { $cardNoSum += substr($id,$i,1) * $Wi[$i]; } $seq = $cardNoSum % 11; $realString = $Ai[$seq]; if($lastString!=$realString) {return false;} //地域效验 $oCity = array(11=>

"Beijing", 12 = > "Tianjin", 13 = > "Hebei", 14 = > "Shanxi", 15 = > "Inner Mongolia", 21 = > "Liaoning", 22 = > "Jilin", 23 = > "Heilongjiang", 31 = > "Shanghai", 32 = > "Jiangsu", 33 = > "Zhejiang", 34 = > "Anhui", 35 = > "Fujian", 36 = > "Jiangxi", 37 = > "Shandong", 41 = > "Henan", 42 = > "Hubei", 43 = > "Hunan", 44 = > "Guangdong", 45 = > "Guangxi", 46 = > "Hainan" 50 = > "Chongqing", 51 = > "Sichuan", 52 = > "Guizhou", 53 = > "Yunnan", 54 = > "Xizang", 61 = > "Shaanxi", 62 = > "Gansu", 63 = > "Qinghai", 64 = > "Ningxia", 65 = > "Xinjiang", 71 = > "Taiwan", 81 = > "Hong Kong", 82 = > "Macao", 91 = > "abroad") $City = substr ($id, 0,2); $BirthYear = substr ($id, 6,4); $BirthMonth = substr ($id, 10,2); $BirthDay = substr ($id, 12,2); $Sex = substr ($id, 16jue 1)% 2; / / male and female 0 / / $Sexcn = $Sex?' Male': 'female'; / Regional Verification if (is_null ($oCity [$City])) {return false;} / / date of birth validity if ($BirthYear > 2078 | | $BirthYear$id,'location'= > $oCity [$City], 'Yee = > $BirthYear,'m'= > $BirthMonth,'d'= > $BirthDay,'sex'= > $Sex) } this is the end of the article on "how to determine the ID number of PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report