title: Trying to get multiple words from a String and searching a text file for any matches in PHP
body: <p>I have code that only partially works; it will find only the 'single' string from a given other string in a search. ie; the text in a string is "red green blue", I am trying to 'compare? or 'match'? it with a small file that has single words only..</p>
  
  <p>The problem is if I type a Single word that 'matches' one in the file it is okay.</p>
  
  <p>I would like it to use the entire 'phrase' in the string to match from any place the word is located. Such as if I type, "red green blue".. it finds the "green" which IS listed in the $textfile, whereas "red" and "blue" are Not.</p>
  
  <p>As it is, if i type "green".. it works fine. if I type "red green blue" it does not 'find' anything.</p>
  
  <p>I have tried, have been trying; stristr functions, imploding the string, etc..</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>$search=$input; //example as above "red green blue" would be the $input
  $lines = file($textfile); //this is the File that contains 20 single words, 
                       //"green" is one of them, "red" and "blue" *are not*.
  foreach($lines as $line)
  {
  // Check if the line contains the string in $input
  if(stristr($line, $search) !== false)
  $answer=$line;
  }
  if(!$found)
  {
  </code></pre>
  
  <p>after that it I would like to have the $answer result in "green"
  It is not an issue, UNLESS the String is within other $input "texts". (mentioned)</p>
  
  <p>Thank you for any help.</p>
  
  <p>I made this edit to "split" the input.. it is still not working as I would hope. It basically works the same way .. Any further suggestions? </p>
  
  <pre><code> $search=$input; 
  
   foreach(preg_split("/((\r?\n)|(\r\n?))/", $input) as $inputs) 
  
   $lines = file($textfile); 
   foreach($lines as $line) { 
   if(stristr($line, $inputs) !== false) 
   $answer=$inputs; 
   } 
   if(!$found) 
   {
  </code></pre>