As the title states, How can I search a text file using PHP and variables. I want to store the user text into a variable and use that as a search parameter in the newplaces.txt file. I know the following code does not work, but hopefully get across what I want to accomplish. I can get a match in the file, but I need help in filtering out the line to only the fields I need
<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;
?>