Write PHP to find a word in a text file using a loop
<p>Write PHP script to search for a word in a text file (titled a.txt). Text file contains 50 words, each word is on 1 line.  On the JavaScript side, a client types a random word in a text field and submits the word. The PHP script searches through the 50 words to find the correct word using a loop that runs until the word is found in the a <code>.txt</code> file.  If the word is not found, an error message must appear stating that the word was not in the list. </p>

<p>The JavaScript part is correct but I'm having trouble with PHP:</p>

<pre><code>$file = fopen("a.txt","r") or die("File does not exist in the current folder.");
$s = $_POST["lname"];
$x = file_get_contents("a.txt");
$a = trim($x);
if(strcmp($s, $a) == 0)
print("&lt;h1&gt;" . $_POST["lname"] . " is in the list&lt;/h1&gt;");
else
print("&lt;h1&gt;" . $_POST["lname"] . " is not in the list&lt;/h1&gt;");
fclose($file);
?&gt;
</code></pre>
