搜索

首页  >  问答  >  正文

从PHP的If-Else语句中提取值

<p>Offer.php有200到300个if else语句。我的团队领导希望获得if else语句的值。我需要$_GET和=="value"的值。</p> <p><strong>Offer.php:</strong></p>
数组
(
    [0] =>测试
    [1] =>演示
    [2] =>尝试
)
大批
(
    [0] =>一
    [1] =>二
    [2] =>三
)</pre>
<p><strong>问题:我获得了空吞吐量的输出。</strong></p>
P粉722409996P粉722409996521 天前522

全部回复(1)我来回复

  • P粉395056196

    P粉3950561962023-08-09 09:33:30

    你试试这样

    <?php
    
    $code = file_get_contents("offer.php");
    
    $pattern_get = '/isset\($_GET\[\'(.*?)\'\]/';
    $pattern_value = '/$_GET\[\'(.*?)\'\]\s*==\s*"(.*?)"/';
    
    preg_match_all($pattern_get, $code, $matches_get, PREG_SET_ORDER);
    preg_match_all($pattern_value, $code, $matches_value, PREG_SET_ORDER);
    
    $getValues = [];
    $values = [];
    
    foreach ($matches_get as $match) {
        $getValues[] = $match[1];
    }
    
    foreach ($matches_value as $match) {
        $values[] = $match[2];
    }
    
    print_r($getValues);
    print_r($values);
    
    // Creating separate URLs for each $_GET variable and value
    for ($i = 0; $i < count($getValues); $i++) {
        $url = 'example.com/?' . $getValues[$i] . '=' . $values[$i];
        echo $url . '<br>' . PHP_EOL;
    }
    
    ?>

    回复
    0
  • 取消回复