我确实知道对此还有多个其他答案,但它们不适合我的代码。因为我的代码每次搜索必须处理 1000 行以上。
我想组合 2 个输入的字符串,以便 PHP 脚本在 txt 文件中搜索这两个字符串,并在输出时组合它们。
这是我尝试过的:
$search = $_GET["search"];
$search2 = $_GET['search2'];
$logfile = $_GET['logfile'];
// Read from file
$file = fopen($logfile, "r");?>
<head><title>Searching: <?php echo $search ?></title></head>
<?php
while( ($line = fgets($file) && $line2 = fgets($file))!= false)
{ if (stristr($line, $search)) { } if (stristr($line2, $search2)) { }
?><font face='Arial'> <?php $lines = $line + line2; ?><?php echo $lines ?></font><hr><p><?php
}
当我在填写了 search 和 search2 的情况下运行此代码时:我得到以下输出:
1
1
1
1
1
1
这些 1 似乎是无限的。
我希望任何人都有解决方案。
输出应该针对两个字符串:
搜索 = '新'
He is a new player
Gambling is a new sport
New is better than old
搜索2 = '网站'
It is a nice website
The website is down
The FIFA website is being built
正确的输出应该是:
He is a new player
It is a nice website
Gambling is a new sport
The FIFA website is being built
New is better than old
感谢您的阅读。
~Conner
<?php
$search1 = "value 1";
$search2 = "value 2";
$lines = file('my_file.txt');
foreach($lines as $line)
{
if(stristr($line,$search1) || stristr($line,$search2))
echo " $line <br>";
}
?>
请看看这段代码是否有效。
这将为您提供以下行$search1
or $search2
出现。
谢谢 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)