好记性,不如烂笔头。好记性,不如烂笔头。

身份证号码算法PHP

class myid{
//根据地名获取地域代码   

function getid($city,$code)
{
include_once('db.php');
           foreach($aid as  $addr_id =>$area)
                            {

        if($area==$city)
       return $addr_id ;
                             }
}
//生成前17位位    
    function id17($area,$year,$month,$day,$sex){
          $hou4=rand(0,9);
          $hou3=rand(0,9);
          if($sex=='女'){
              $qqq=array(2,4,6,8,0);
              $ddd=rand(0,4);
              $hou2=$qqq[$ddd];

          }elseif($sex=='男'){
              $qqq=array(1,3,5,7,9);
              $ddd=rand(0,4);
              $hou2=$qqq[$ddd];

          }else{
              $qqq=array(0,1,2,3,4,5,6,7,8,9,);
              $ddd=rand(0,9);
              $hou2=$qqq[$ddd];

                     }
    $rand=$hou4.$hou3.$hou2;
if($month<10) $month='0'.$month;
if($day<10) $day='0'.$day;
$id17=$area.$year.$month.$day.$rand;

    return $id17;
}
//计算最后一位校验码
function lastcode($id17){

    $sum=array('7','9','10','5','8','4','2','1','6','3','7','9','10','5','8','4','2');
    $result=    array('0','1','2','3','4','5','6','7','8','9','10');
    $checkcode= array('1','0','X','9','8','7','6','5','4','3','2');
/*echo $id."<br></10>'7','9','10','5','8','4','2','1','6','3','7','9','10','5','8','4','2'<br/>";
echo "'0','1','2','3','4','5','6','7','8','9','10'<br/>
      '1','0','X','9','8','7','6','5','4','3','2'<br/>";
/
$tmp='';
for($i=0;$i<=16;$i++){

  $tmp1=$id17[$i]$sum[$i];
  //echo $id[$i]."+".$sum[$i]."=".$tmp1."<br/>";
  $tmp=$tmp+$tmp1;

}
$tmp3=$tmp%11;
$tmp4=0;
foreach($result as $cc){
    $tmp4=$tmp4+1;
    if($cc==$tmp3) break;

}
$tmp4=$tmp4-1;
$lastcode=$checkcode[$tmp4];
    return $lastcode;

}
}class myid{
//根据地名获取地域代码

function getid($city,$code)
{
include_once('db.php');
           foreach($aid as  $addr_id =>$area)
                            {

        if($area==$city)
       return $addr_id ;
                             }
}
// 生成前17位     
    function id17($area,$year,$month,$day,$sex){
          $hou4=rand(0,9);
          $hou3=rand(0,9);
          if($sex=='女'){
              $qqq=array(2,4,6,8,0);
              $ddd=rand(0,4);
              $hou2=$qqq[$ddd];

          }elseif($sex=='男'){
              $qqq=array(1,3,5,7,9);
              $ddd=rand(0,4);
              $hou2=$qqq[$ddd];

          }else{
              $qqq=array(0,1,2,3,4,5,6,7,8,9,);
              $ddd=rand(0,9);
              $hou2=$qqq[$ddd];

                     }
    $rand=$hou4.$hou3.$hou2;
if($month<10) $month='0'.$month;
if($day<10) $day='0'.$day;
$id17=$area.$year.$month.$day.$rand;

    return $id17;
}
//计算最后一位校验码

function lastcode($id17){

    $sum=array('7','9','10','5','8','4','2','1','6','3','7','9','10','5','8','4','2');
    $result=    array('0','1','2','3','4','5','6','7','8','9','10');
    $checkcode= array('1','0','X','9','8','7','6','5','4','3','2');
/*echo $id."<br></10>'7','9','10','5','8','4','2','1','6','3','7','9','10','5','8','4','2'<br/>";
echo "'0','1','2','3','4','5','6','7','8','9','10'<br/>
      '1','0','X','9','8','7','6','5','4','3','2'<br/>";
/
$tmp='';
for($i=0;$i<=16;$i++){

  $tmp1=$id17[$i]$sum[$i];
  //echo $id[$i]."+".$sum[$i]."=".$tmp1."<br/>";
  $tmp=$tmp+$tmp1;

}
$tmp3=$tmp%11;
$tmp4=0;
foreach($result as $cc){
    $tmp4=$tmp4+1;
    if($cc==$tmp3) break;

}
$tmp4=$tmp4-1;
$lastcode=$checkcode[$tmp4];
    return $lastcode;

}
}
未经允许不得转载:好记性,不如烂笔头。 » 身份证号码算法PHP

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址