身份证号码15位升级为18位,一个函数搞定
/** * 功能:把15位身份证转换成18位 * * @param string $idCard * @return newid or id */ 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; } }