I have a html search box that uses the script below, but it seems like the echo output goes in a loop or shows all results from the .txt file that you can see I am using fopen for. I tried to add exit at the end of the echo's but then it was only able to get the first line in content.txt no matter what I searched for using the search box. I am trying to have it only show the result of what being searched for.
Here is the code I've been working on:
<?php
$q = $_REQUEST["q"];
$f = fopen("content.txt", "r");
while (($line = fgets($f)) !== FALSE) {
if (strstr($line, $q)) {
echo "<li>Found $line</li>";
} else {
echo "<p>Nothing found.</p>";
}
}
?>