Home > php教程 > PHP源码 > body text

PHP身份证号码15位升级为18位

PHP中文网
Release: 2016-05-25 17:05:04
Original
1198 people have browsed it

身份证号码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;
		}
	}
Copy after login

                   


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template