带有数字和字母的代码序列,没有 0,1,o 和 i

code sequences with number and letter without 0,1,o & i

提问人:axech 提问时间:9/4/2018 最后编辑:axech 更新时间:9/5/2018 访问量:72

问:

我需要制作代码序列

例如。从A5B开始,下一个代码将是A5C,A5D... 直到 A59 然后下一个 A6A,A6B......A99 然后下一个 BAA,BAB,BAC

序列是 A-Z,然后以 2-9 连续

$x = $last; // Get Last Value From DB
$a = substr($x,0,1); // Get First String
$b = substr($x,1,1); // Get Middle String
$c = substr($x, -1); // Get Last String
if($c == 'Z'){
$x = $a.$b.'0';
}
elseif($c == '9'){
if ($b == 'Z'){
$x = $a.'0'.'A';
}
elseif($b == '9'){
$a++;
$x = $a.'A'.'A';
}
else{
$b++;
$x = $a.$b.'A';
}
}
else{
$x++;
}

它有效,但问题是如何在不使用 0,1,o 和 i 的情况下制作代码序列

请帮忙 对不起我的英语

PHP codeigniter 序列 增量

评论

0赞 splash58 9/4/2018
如果我理解正确$a = 'AAA'; echo ++$a; // AAB
0赞 axech 9/4/2018
@splash58如何在不使用 0,1,o 和 i 的情况下制作代码序列?
0赞 splash58 9/4/2018
它将没有数字$a = 'AAZ'; echo ++$a; // ABA
0赞 axech 9/4/2018
@splash58什么意思?我需要代码序列,例如:AAA,如果最后一个 caracter 达到 Z,它将是 AA2,并且代码序列没有 0,1,o 和 i 例如:AAZ,接下来是 AA2 而不是 AA1,因为 ill 不使用 1 *(0,1,o & i)
0赞 splash58 9/4/2018
我误读了你的问题

答:

1赞 Holmes 9/4/2018 #1

如果您不担心性能,一个简单的解决方法是使用 do-while 循环来不断迭代,直到不再包含任何不需要的字符:$x

$x = $last; // Get Last Value From DB
do {
    $a = substr($x, 0, 1); // Get First String
    $b = substr($x, 1, 1); // Get Middle String
    $c = substr($x, -1); // Get Last String
    if ($c == 'Z') {
        $x = $a.$b.'0';
    } elseif ($c == '9') {
        if ($b == 'Z') {
            $x = $a.'0'.'A';
        } elseif ($b == '9') {
            $a++;
            $x = $a.'A'.'A';
        } else {
            $b++;
            $x = $a.$b.'A';
        }
    } else {
        $x++;
    }
} while (preg_match('/[01OI]/', $x));

评论

0赞 axech 9/5/2018
我测试了它,但为什么它保持负载?
0赞 Holmes 9/5/2018
我不确定你的意思。它对你不起作用吗?
0赞 axech 9/5/2018
如果我使用 do-while,页面会继续加载,但当我使用 if-else 时它会起作用
0赞 Holmes 9/5/2018
然后由于某种原因,它陷入了无限循环。有关工作版本,请参阅此处:rextester.com/WRSX85807