【发布时间】:2015-02-05 17:51:30
【问题描述】:
如标题所述,如何使用 PHP 和变量搜索文本文件。我想将用户文本存储到一个变量中,并将其用作 newplaces.txt 文件中的搜索参数。我知道下面的代码不起作用,但希望能完成我想要完成的任务。我可以在文件中找到匹配项,但我需要帮助将行过滤到我需要的字段
<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;
?>
【问题讨论】:
-
为什么投反对票?改为提问
-
参考这个网址google.co.in/…
-
我更新了我的示例代码。为了更准确地回答我的问题,我想我想要做的是过滤匹配的行以仅将某个字段存储为 $lat @manuyd
-
你是说线路?不清楚你想说什么
-
是的,grep 将返回匹配的整行,然后我想将其过滤到我想要的字段