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..
The problem is if I type a Single word that 'matches' one in the file it is okay.
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.
As it is, if i type "green".. it works fine. if I type "red green blue" it does not 'find' anything.
I have tried, have been trying; stristr functions, imploding the string, etc..
Here is what I have:
$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)
{
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)
Thank you for any help.
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?
$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)
{