PHP搜索系统,读取.txt并输出每一行中包含特定字符串的内容

PHP搜索系统,读取.txt并输出每一行中包含特定字符串的内容,php,Php,因此,我在这个网站上创建了一个最佳torrent Magnet URI备选方案列表。我更愿意列出一些.html文件中的所有内容: <a href="torrent1:magnet:uri">torrent1:name_of_torrent</a> <a href="torrent2:magnet:uri">torrent2:name_of-torrent</a> ... ... 让PHP检查$\u POST['search\u torrent

因此,我在这个网站上创建了一个最佳torrent Magnet URI备选方案列表。
我更愿意列出一些.html文件中的所有内容:

<a href="torrent1:magnet:uri">torrent1:name_of_torrent</a>
<a href="torrent2:magnet:uri">torrent2:name_of-torrent</a>
...

...
让PHP检查$\u POST['search\u torrent']并在.html中搜索该数据,如果在其中任何一行中找到了任何特定的数据/名称,则使用foreach()将整行作为项输出

<?php
if (isset($_POST['search_torrent'])) {
    $search_torrent = $_POST['search_torrent'];
    $torrent_file = "read.txt";

    echo nl2br(shell_exec("type ".$torrent_file."| find /I \"".$search_torrent."\""));
?>
我做了类似的操作,但我试图在其上完成此操作的主机不允许exec()shell\u exec()

<?php
if (isset($_POST['search_torrent'])) {
    $search_torrent = $_POST['search_torrent'];
    $torrent_file = "read.txt";

    echo nl2br(shell_exec("type ".$torrent_file."| find /I \"".$search_torrent."\""));
?>

我知道我知道。。。我可以使用数据库,但我现在不太喜欢


谢谢

将文件行读入数组并grep:

foreach(preg_grep('/'.preg_quote($_POST['search_torrent'], '/').'/i', file('read.txt')) as $line) {
    echo "$line<br>";
}
foreach(preg_grep('/'.preg_quote($\u POST['search\u torrent'],'/')。/i',file('read.txt'))作为$line){
回显“$line
”; }
正是我所需要的。非常感谢。我会在9分钟内接受答案