我有一些脚本如下所示。如果找到两个变量,它将搜索2个变量并输出整行。我需要包含第三个变量,然后只输出行中的第一个分隔变量。分隔符是管道(|)。任何帮助感激不尽。提前谢谢。
<?php
$variable1 = $_REQUEST["variable1"];
$variable2 = $_REQUEST['variable2'];
// Read from file
$lines = file('results.txt');
echo"<html><head><title>SEARCH RESULTS FOR: $variable1 and $variable2</title></head><body>";
foreach($lines as $line)
{
// Check if the line contains the string we're looking for, and print if it does
if(stristr($line,$variable1) && stristr($line,$variable2)) // case insensitive
echo "<font face='Arial'> $line </font><hr>";
}
?>
</body></html>