Home  >  Article  >  Backend Development  >  PHP tip: How to get gender and date of birth from ID card

PHP tip: How to get gender and date of birth from ID card

PHPz
PHPzOriginal
2017-03-05 14:38:084956browse

This article mainly introduces how php obtains gender and date of birth from the ID card. It has a very good reference value. Let’s take a look at it with the editor of php Chinese website.

Please look at the code:

//通过身份证号查询出性别与生日
 $birth = strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8);
$sex = substr($idcard, (strlen($idcard)==15 ? -2 : -1), 1) % 2 ? '1' : '0'; //1为男 2为女

//通过身份证号查询出性别与生日
 if($data['cardtype'] == 'idcard'){
 $data['birth'] = strlen($data['cardno'])==15 ? ('19' . substr($data['cardno'], 6, 6)) : substr($data['cardno'], 6, 8);
 $data['sex'] = substr($data['cardno'], (strlen($data['cardno'])==15 ? -2 : -1), 1) % 2 ? '1' : '0';

For more articles about how to get gender and birth date from ID card from php, please pay attention to php Chinese website!

Statement:
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