15位身份证号转化为18位身份证号

    /**
     * @desc 身份证15位转18位
     * @param $idCard
     * @return string
     */
    public static function getIDCard($idCard) {
        // 若是15位,则转换成18位;否则直接返回ID
        if (15 == strlen ( $idCard )) {
            $W = array (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1 );
            $A = array ("1","0","X","9","8","7","6","5","4","3","2" );
            $s = 0;
            $idCard18 = substr ( $idCard, 0, 6 ) . "19" . substr ( $idCard, 6 );
            $idCard18_len = strlen ( $idCard18 );
            for($i = 0; $i < $idCard18_len; $i ++) {
                $s = $s + substr ( $idCard18, $i, 1 ) * $W [$i];
            }
            $idCard18 .= $A [$s % 11];
            return $idCard18;
        } else {
            return $idCard;
        }
    }

  

posted @ 2017-07-12 16:12  流火行者  阅读(3044)  评论(0编辑  收藏  举报