PHP comparing a list of letters to an array of words
<p>I'm trying to make it so I can take a list of letters, <code>$rack</code>, imported from the form and compare it to the array <code>$words</code>, which is the dictionary imported from a text file.  I then want to build an array, <code>$playable</code>, that will store all of the words that contain any of the letters in <code>$rack</code>.</p>

<p>This is what I have</p>

<pre><code>&lt;?php

session_start();
$rack = $_GET["letters"]; // list of letters imported from form

$words = array();  // imported text file with the list of playable words

$playable = array(); // array created by finding playable words from dictionary


//populates $words with the text file dictionary.txt
$filename = 'dictionary2.txt';

$fp = @fopen($filename, 'r'); 

$words = fread($fp); 


// array to score word

$score = array("a" =&gt; 1, "b" =&gt; 1, "c" =&gt; 1, "d" =&gt; 1, "e" =&gt; 1, "f" =&gt; 1, "g" =&gt; 1, "h" =&gt; 1, 
"i" =&gt; 1, "j" =&gt; 1, "k" =&gt; 1, "l" =&gt; 1, "m" =&gt; 1, "n" =&gt; 1, "o" =&gt; 1, "p" =&gt; 1, "q" =&gt; 1, 
"r" =&gt; 1, "s" =&gt; 1, "t" =&gt; 1, "u" =&gt; 1, "v" =&gt; 1, "w" =&gt; 1, "x" =&gt; 1, "y" =&gt; 1, "z" =&gt; 1); 

// loop that checks each index, or words, against the list of letters the player
// informs us he has while building the second array.

for ( $i=0; $i&lt;sizeof($words); $i++){  
    if (in_array($rack, $words[$i])){
        $playable[] = $words[$i];
        }
}


?&gt;
&lt;html&gt;

&lt;title&gt;Hanging With Friends Help&lt;/title&gt;

&lt;body style="background-color:black;"&gt;
&lt;font color = "white"&gt;
&lt;center&gt;&lt;img src="wordslogo.jpg" alt="Cheater!" /&gt; &lt;/center&gt;
&lt;form name="input" action="http://i211.soic.indiana.edu/~kmnacke/hangingwithfriends.php" method="get"&gt;


    &lt;p&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;center&gt;&lt;input type="text" name="letters" /&gt;&lt;/center&gt;

    &lt;/p&gt;
    &lt;center&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/center&gt;

    &lt;center&gt;&lt;label&gt;

    &lt;?php 


 //prints the list of playable words

    for ( $i=0; $i&lt;sizeof($playable); $i++){  
        echo $playable[$i];

}

    for ( $i=0; $i&lt;sizeof($words); $i++){  
            echo $words[$i];

    }


    ?&gt;


    &lt;/label&gt;&lt;/center&gt;


    &lt;/form&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>
