php实现中国身份证号码校验算法

代码语言:php

所属分类:算法

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php
function is_idcard($id_card) {

    $z = substr($id_card, 17);
    $xishu = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
    $a = substr($id_card, 0, 17);
    $b = str_split($a);

    $c = null; $d = null;
    foreach ($xishu as $key => $value) {
        $c[] = $b[$key]*$value;
    }
    foreach ($c as $key) {
        $d = $d + $key;
    }
    $e = $d % 11;

    switch ($e) {
        case 0: $e = 1; break;
        case 1: $e = 0; break;
        case 2: $e = "X"; break;
        case 3: $e = 9; break;
        case 4: $e =.........完整代码请登录后点击上方下载按钮下载查看

网友评论0