我有以下脚本:
<?php
$search = $_REQUEST["search"];
$search2 = $_REQUEST['search2'];
// Read from file
$lines = file('archive.txt');
echo"<html><head><title>SEARCH RESULTS FOR: $search</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,$search) && stristr($line,$search2)) // case insensitive
echo "<font face='Arial'> $line </font><hr>";
}
?>
</body></html>
目前,您可以搜索两个变量,然后输出整行。请你帮我输出第一行的艺术品(管道分隔)?
答案 0 :(得分:2)
在foreach循环中尝试这个...
if(stristr($line,$search) && stristr($line,$search2)) { // case insensitive
$line = explode("|", $line);
$line = $line[0];
echo "<font face='Arial'> $line </font><hr>";
}