Ekstrak nilai daripada penyataan If-Else PHP
P粉722409996
2023-08-08 14:55:14
<p>Tawaran.php有200到300个jika lain语句。我的团队领导希望获得jika lain语句的值。我需要$_GET和;和=="value。
<p><strong>Tawaran.php :</strong></p>
<pre class="brush:php;toolbar:false;"><?php
if (isset($_GET['test']) && $_GET['test'] == "one") {
sertakan "hi.php";
} elseif (isset($_GET['demo']) && $_GET['demo'] == "dua") {
sertakan "hello.php";
} elseif (isset($_GET['try']) && $_GET['try'] == "tiga") {
sertakan "bye.php";
} lain {
sertakan "default.php";
}
?></pra>
<p><strong>Nilai.php</strong> (尝试一下):</p>
<pre class="brush:php;toolbar:false;"><?php
$code = file_get_contents("offer.php");
// Ungkapan biasa untuk memadankan pembolehubah $_GET dan nilai sepadannya
$pattern = '/isset($_GET['([^']+)'])s*&&s*$_GET['1']s*==s*"([^"]+) "/';
preg_match_all($pattern, $code, $matches);
$getValues = [];
$nilai = [];
foreach ($match as $match) {
$getValues[] = $match[1];
$values[] = $match[3];
}
print_r($pembolehubah);
print_r($nilai);
?></pra>
<p><strong>Jangkakan output :</strong></p>
<pre class="brush:php;toolbar:false;">Array
(
[0] => ujian
[1] => demo
[2] => cubalah
)
Susunan
(
[0] => satu
[1] => dua
[2] => tiga
)</pra>
<p><strong>问题:我得到了空数组的输出。</strong></p>
Anda cuba ini