I use the following code to search the text file:
$query="red";
$FileName = "search.txt";
$fh = fopen($FileName, 'r') or die("Can't open file");
$data = fread($fh, filesize($FileName));
$Pos = strpos($data,$query);
if ($Pos)
{
echo "Found";
}
else
{
echo "Not Found";
}
Let the text file be:
orange_red blue_gray yellow_blue white_black
It finds red at orange_red,but i want to match the whole word.
For example:
If the text to be searched is to be red
I want it to return false because red does not exist independently it is part of word orange_red.
In brief i want to search words delimited by space
Searching red and orange should return false and searching orange_red should return true.
Try this, splits the data at a space, and then sees if the query is in the array.