在项目中引入 autoload:, (*7)
require 'path_to_sdk/autoload.php';
初始化
use \Idcard\IdcardInit as Idcard;
...
...
$idcardObj = new Idcard('11xxxxxxxxxxxxxxxx');
...
OR, (*8)
$idcardObj = new \Idcard\IdcardInit('11xxxxxxxxxxxxxxxx');
检查身份证是否生效,生效返回TRUE,失效情况下在初始化阶段抛出异常
$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);
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/PerterWan/idcard, (*9)
License
The library is available as open source under the terms of the MIT License., (*10)