0
正如标题所述,如何使用PHP和变量搜索文本文件。我想将用户文本存储到变量中,并将其用作newplaces.txt文件中的搜索参数。我知道以下代码不起作用,但希望能够完成我想要完成的任务。我可以在文件中匹配,但我需要在该行筛选出来只有我需要PHP搜索/过滤文本文件
<form method="post" action"http...">
Enter City and State <input name='place' type="text" size="10">
<input type="submit" value="Submit">
</form>
<?php
$f="/newplaces.txt";
$o=file($f);
$a=$_POST['place'];
$c=preg_grep("/\b$a\b/", $o);
echo implode($c, ' ');
$lat=exec("grep -i $a $f | cut -d' '' -f10 "); //Need help with filtering the match
echo $lat;
?>
为什么downvote?问一个问题,而不是 – swam 2014-12-08 05:18:14
参考此网址https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php+search+text+in+file – manuyd 2014-12-08 05:23:31
Ive更新了我的示例代码。为了更精确地解决我的问题,我想我要做的就是过滤匹配的行,以获得仅存储为$ lat @manuyd – swam 2014-12-08 05:30:32