中國大陸身份證號碼驗證及身份證信息獲取,數據來源於國家標準GB/T 2260-2007

Github

😄😄歡迎STAR👍👍

一個簡單的身份證號碼獲取用戶信息工具


[English Documentation](https://github.com/ofcold/identity-card/blob/2.0/README.md)


中國(大陸地區)公民身份證,數據來源於國家標準GB/T 2260-2007 (中華人民共和國行政區劃代碼)


安裝

composer require ofcold/identity-card

說明

一個基於中華人民共和國公民身份證的組件能夠獲取用戶信息。這個適用於任何php框架,可是隻有當php版本>=7.1時才能夠。php

使用

驗證你的身份證號碼

//  返回false 或 Ofcold\IdentityCard\IdentityCard
    $result = Ofcold\IdentityCard\IdentityCard::make('32010619831029081');

    if ( $result === false ) {

        return '您的身份證號碼不正確';
    }

    print_r($result->toArray());

或運行測試文件

php test
$idCard = Ofcold\IdentityCard\IdentityCard::make('320106198310290811', 'en');
//  Use locale, Current supported zh-cn,en
// $idCard = Ofcold\IdentityCard\IdentityCard::make('320106198310290811', 'zh-cn');
if ( $idCard === false ) {

    return '您的身份證號碼不正確';
}

$area = $idCard->getArea();
$gender = $idCard->getGender();
$birthday = $idCard->getBirthday();
$age = $idCard->getAge();
$constellation = $idCard->getConstellation();

返回結果:

{
    "area": "山西省 運城地區 運城市",
    "province": "山西省",
    "city": "運城地區",
    "county": "運城市",
    "gender": "男",
    "birthday": "1980-03-12",
    "zodiac": "豬",
    "age": 38,
    "constellation": "雙魚座"
}

Api

  • getArea():string 獲取地區
  • getConstellation():string 獲取星座
  • getZodiac() : string 獲取生肖
  • getAge():int 獲取年齡
  • getBirthday(string $foramt = 'Y-m-d'):string 獲取生日
  • getGender():string 獲取性別
  • getCounty():string|null 獲取縣城
  • getCity():string|null 獲取城市
  • getProvince():string|null 獲取省
  • toArray():array 所有信息
  • toJson(int $option):string 所有信息

修改歷史

V2.0.0git

  • 新增 #2 __get()
  • 新增 #2 __toString()
  • 修改 #2 static make() 方法返回當前對象或者boolean類型
  • 移除 #2 構造方法異常驗證
相關文章
相關標籤/搜索