PHP代码替换数组中的某些值,代码生成器

时间:2014-07-06 06:18:22

标签: php arrays optimization generator combinations

我正在尝试编写PHP代码作为业余爱好项目,基本上创建一个“可能的”代码生成器。场景是我们有一个可以使用的25个有效字符列表。

想象一下,你有一个25个字符的代码,但你不小心在代码中的任何位置划掉了前两个字符或三个字符。现在我们需要找到所有可能的组合来试用。我已将所有有效字符放入下面可以在代码中使用的数组中。

$valid=array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","Z",
"2","3","4","6","7","8","9");
$arraylength=count($valid);

将仍然可用或看到的字符输入到文本框中,并且在字符不可读的位置留空并且获取变量值。

$char1= $_POST['code1'];
$char2= $_POST['code2'];
$char3= $_POST['code3'];
$char4= $_POST['code4'];
$char5= $_POST['code5'];
$char6= $_POST['code6'];
$char7= $_POST['code7'];
$char8= $_POST['code8'];
$char9= $_POST['code9'];
$char10= $_POST['code10'];
$char11= $_POST['code11'];
$char12= $_POST['code12'];
$char13= $_POST['code13'];
$char14= $_POST['code14'];
$char15= $_POST['code15'];
$char16= $_POST['code16'];
$char17= $_POST['code17'];
$char18= $_POST['code18'];
$char19= $_POST['code19'];
$char20= $_POST['code20'];
$char21= $_POST['code21'];
$char22= $_POST['code22'];
$char23= $_POST['code23'];
$char24= $_POST['code24'];
$char25= $_POST['code25'];

并投入阵列......

$jada = array($char1, $char2, $char3, $char4, $char5, $char6, $char7, $char8, $char9, $char10, $char11, $char12, $char13, $char14, $char15
, $char16, $char17, $char18, $char19, $char20, $char21, $char22, $char23, $char24, $char25);

我已经被困了一段时间了,我现在做的小事是,如果一个变量是空的,那么做一些事情(作为测试回音或打印可能的组合)

if(!isset($char1) || trim($char1) == ""){
    for($x=0;$x<$arraylength;$x++) {
    echo $valid[$x];
    echo "<br>";
    } }
    else{
        echo ($char1);
        }

你们可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

经过多年的中断,看到它仍然处于开放状态,我认为我最好还是分享一些信息。

最后我弄清楚了,您可以在这里获取源代码并在您自己的服务器中对其进行测试:https://github.com/Masterkriz/XBOX_Pre-paid_code_fixer