Offer.php有200-300个if else语句。我的团队领导想获取if else语句的值。我需要$_GET
和== "value"
的值。
Offer.php:
<?php
if (isset($_GET['test']) && $_GET['test'] == "one") {
include "hi.php";
} elseif (isset($_GET['demo']) && $_GET['demo'] == "two") {
include "hello.php";
} elseif (isset($_GET['try']) && $_GET['try'] == "three") {
include "bye.php";
} else {
include "default.php";
}
?>
字符串
Value.php(正在尝试):
<?php
$code = file_get_contents("offer.php");
// Regular expression to match $_GET variables and their corresponding values
$pattern = '/isset\(\$_GET\[\'([^\']+)\'\]\)\s*&&\s*\$_GET\[\'\1\'\]\s*==\s*"([^"]+)"/';
preg_match_all($pattern, $code, $matches);
$getValues = [];
$values = [];
foreach ($matches as $match) {
$getValues[] = $match[1];
$values[] = $match[3];
}
print_r($variables);
print_r($values);
?>
型
预期输出:
Array
(
[0] => test
[1] => demo
[2] => try
)
Array
(
[0] => one
[1] => two
[2] => three
)
型
**问题:**我得到空数组输出。
1条答案
按热度按时间bnl4lu3b1#
这将解决你的问题。
字符串