Reposted: calculate ID card check code with PHP

xiaoxiao2021-03-06  103

http://www.lmws.net/phpweb/Article.php?id=79

Use a PHP to calculate ID card check code China (mainland) Citizen ID card number, and many articles on the Internet have introduced, there are not many sayings here. The last bit of the ID number is the check code, and it is calculated according to the first 17 bits. The algorithm is probably this: multiplied each of the first 17 bits and a string weighting factor, then calculates these products; the number obtained by the sum of these products as the serial number, and finally extracts in a check code string. A character corresponding to the serial number. Of course, there are many articles on the Internet to teach you to calculate this check code. Here we will try to complete this in PHP language, maybe it can be used in PHP development, such as whether the user's ID number is correct. Assuming a Chinese (mainland) citizen ID number is 17: 4401021990101001 (Note: This person is born in 2199), then we followed a few line PHP code to complete the calculation of the check code according to the above algorithm. In order to make everyone easier to understand, I use a simple statement, please see the code:

After running the above code, you can calculate the check code of the ID card. You can try it with your identity card. If you understand the above example, you can merge some of this code, remove the necessary variables, optimize the following code:

转载请注明原文地址:https://www.9cbs.com/read-96896.html

New Post(0)