php通过身份证判断性别

/**

已测试,百度很多写法不行的
 * 1就是男性 2就是女性
* 通过身份证获取性别类型
* @param type $card
* @return int
*/
function getCardSex($idcard) {
 if(empty($idcard)) return null;
    $sexint = (int) substr($idcard, 16, 1);
    return $sexint % 2 === 0 ? '2' : '1';
}

原文地址:https://www.cnblogs.com/weiyiyong/p/11321263.html