手机号组成规则 - 分档 // +--------------------------------------------------------------------------------------------// | Date:2016/8/24// +------------------------------------------------------------------------------------------
// +-------------------------------------------------------------------------------------------- // | Date:2016/8/24 // +-------------------------------------------------------------------------------------------- namespace rule; class Rules { /** * 获取手机号码靓号规则 * =param $phone * =return array */ function getRule($phone) { $n1 = substr($phone, 0, 1); $n2 = substr($phone, 1, 1); $n3 = substr($phone, 2, 1); $n4 = substr($phone, 3, 1); $n5 = substr($phone, 4, 1); $n6 = substr($phone, 5, 1); $n7 = substr($phone, 6, 1); $n8 = substr($phone, 7, 1); $n9 = substr($phone, 8, 1); $n10 = substr($phone, 9, 1); $n11 = substr($phone, 10, 1); $rules = [ [ 'name' => 'AAAAAAAA', 'rule' => '($n4==$n5) && ($n5==$n6) && ($n6==$n7) && ($n7==$n8) && ($n8==$n9) && ($n9==$n10) && ($n10==$n11)' ], [ 'name' => 'AAAAAAA', 'rule' => '($n5==$n6) && ($n6==$n7) && ($n7==$n8) && ($n8==$n9) && ($n9==$n10) && ($n10==$n11) && ($n4!=$n5)' ], [ 'name' => 'AAAAAA', 'rule' => '($n6==$n7) && ($n7==$n8) && ($n8==$n9) && ($n9==$n10) && ($n10==$n11) && ($n5!=$n6)' ], [ 'name' => 'AAAAA', 'rule' => '($n7==$n8) && ($n8==$n9) && ($n9==$n10) && ($n10==$n11) && ($n6!=$n7)' ], [ 'name' => 'AAAA', 'rule' => '($n11==$n10) && ($n10==$n9) && ($n9==$n8) && ($n8!=$n7)' ], [ 'name' => 'AAA', 'rule' => '($n11==$n10) && ($n10==$n9) && ($n9!=$n8)' ], [ 'name' => 'AA', 'rule' => '($n11==$n10) && ($n10!=$n9) && ($n9!=$n8)' ], [ 'name' => 'ABCDEF', 'rule' => '($n11-$n10)==1 && ($n10-$n9)==1 && ($n9-$n8)==1 && ($n8-$n7)==1 && ($n7-$n6)==1' ], [ 'name' => 'ABCDE', 'rule' => '($n11-$n10)==1 && ($n10-$n9)==1 && ($n9-$n8)==1 && ($n8-$n7)==1 && ($n7-$n6)!=1' ], [ 'name' => 'ABCD', 'rule' => '($n11-$n10)==1 && ($n10-$n9)==1 && ($n9-$n8)==1 && ($n8-$n7)!=1' ], [ 'name' => 'ABC', 'rule' => '($n11-$n10)==1 && ($n10-$n9)==1 && ($n9-$n8)!=1' ], [ 'name' => 'AABB', 'rule' => '($n8==$n9) && ($n10==$n11) && ($n9!=$n10)' ], [ 'name' => 'ABAB', 'rule' => '($n8==$n10) && ($n9==$n11) && ($n10!=$n11)' ] ]; //参数替换 foreach ($rules as $key => $value) { @eval('$result=(' . $value['rule'] . ');'); if ($result) { $data = $value; } } if (empty($data)) { $data = [ 'name' => 'P', 'rule' => 'P' ]; } return $data; } }php - 2
[ "/(\d)\\1(\d)(\\2){2}/", "/(\d)(\d)(\\1\\2){2}/", "/(0(?=3)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3,8}/", "/(\\d)\\1{4}/", "/(\\d)\\1{3}/", ], "2" => [ "/(\d)\\1(\d)\\2/", "/(\d)(\d)\\1\\2/", "/(\\d)\\1{2}/", "/(\d)\\1{2}(\d)\\2/", ], "3" => [ "/.*88$/" ] ]; // 解析档次 foreach ($ruleArr as $hbKey => $tmpRuleArr) { foreach ($tmpRuleArr as $rule) { $result = preg_match($rule, $mobile); if ($result) { return $hbKey; } } } // 判断是否有可能是生日 $monthNum = intval(substr($mobile, 3, 2)); $dayNum = intval(substr($mobile, 5, 2)); if ($monthNum < 13 && $dayNum < 32) { return $lowestLevel-1; } return $lowestLevel; }