【手机选号网】手机号规律匹配方案

方案一:

<?php

function checkIt($number) {

    $modes = array( 'AAAAAAAAA','AAAABBBB', 'AABBCCDD', 'ABABCDCD', 'AAABAAAB', 'AABBAABB', 'ABCDABCD',

                    'AAAAAA', 'ABCDEFG',

                    'AAAAAA', 'ABBABB', 'AAAABB', 'AAABBB', 'AABBCC', 'ABABAB', 'ABCABC',

                    'AAAAA', 'AABBB', 'AAAAB', 'AAABB',

                    'AAAA', 'ABAB', 'AABB', 'ABBA', 'AAAB', '####'/*升降序*/,

                    'AAA', '###'/*升降序*/,

                    'AA' ); //前后排序有优先级,只要有一个匹配,后面的就不再检索了

    $result = 'unknown';

    foreach ($modes as $mode) {

        $len = strlen($mode);

        $s = substr($number, -$len);

        $temp = array();

        $match = true;

        for ($i=0; $i<$len; $i++) {

            if ($mode[$i]=='#') {

                if (!isset($temp['step'])) {

                    $temp['step'] = 0;

                    $temp['current'] = intval($s[$i]);

                } elseif ($temp['step'] == 0) {

                    $temp['step'] = $temp['current'] - intval($s[$i]);

                    if ($temp['step'] != -1 && $temp['step'] != 1) {

                        $match = false;

                        break;

                    } else {

                        $temp['current'] = intval($s[$i]);

                    }

                } else {

                    $step = $temp['current'] - intval($s[$i]);

                    if ($step != $temp['step']) {

                        $match = false;

                        break;

                    } else {

                        $temp['current'] = intval($s[$i]);

                    }

                }

            } else {

                if (isset($temp[$mode[$i]])) {

                    if ($s[$i] != $temp[$mode[$i]]) {

                        $match = false;

                        break;

                    }

                } else {

                    $temp[$mode[$i]] = $s[$i];

                }

            }

        }

        if ($match) {

            $result = $mode;

            break;

        }

    }

    return $result;

}

echo checkIt('13888888833');

  

你可能感兴趣的:(手机)