PHP code example of peter-wan / idcard

1. Go to this page and download the library: Download peter-wan/idcard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peter-wan / idcard example snippets


  

  use \Idcard\IdcardInit as Idcard;
  ...
  ...
 
      $idcardObj = new Idcard('11xxxxxxxxxxxxxxxx');
 
  ...
  

  $idcardObj = new \Idcard\IdcardInit('11xxxxxxxxxxxxxxxx');
  

    $check = $idcardObj->getParams("check");
  

    //可自定义返回性别值
    $gender = $idcardObj->gender()->getGender($male = '男', $female = '女');
  

    $birthdayObj = $idcardObj->birth()->getIdCardBirthInfo();
    //年龄
    $age = $birthdayObj->age;
    //出生年月日
    $birthday = $birthdayObj->birthday;
    //出生年份
    $year = $birthdayObj->birthday_year;
    //出生月份
    $month = $birthdayObj->birthday_month;
    //出生日
    $day = $birthdayObj->birthday_day();
    //生肖
    $ChineseZodiac = $birthdayObj->chinese_zodiac();
    //星座
    $Constellation = $birthdayObj->constellation;
  

    //获取省份:河北省
    $province = $idcard->getArea()->getProvince();
    //获取城市:河北省石家庄市
    $city = $idcard->getArea()->getCity();
    //获取详细地址信息
    $area = $idcard->getArea()->getArea();
  

      //补全15位身份证号码
      $newIdcard = $idcardObj->tools()->get18LengthFrom15Length();
      //隐藏位数 1333***********1111 可自定义隐藏替代字符,左右值为非负整数,$left + $right <= 10 & >=0
      $format = $idcardObj->tools()->getIdcardFormat($format = '*', $left = 4, $right = 4);