Are your data in a database? In that case it is much faster to use a query to check whether the words are in some record. Regular expressions can take quite some time!My search enginue will bring up a result IF and only if ALL of the words in $search exist in the result. For example if
$search = Vax Useful Commands
Then the result is only true if (eregi(".*Vax.*Useful.*Commands.*", 'possible result')) is true
I like the 'explode()' function very much , which splits a string on a separator (can be ' ') and puts the results in a long array.Now, I don't know how many words there are in $search initially. How do I do a search like that? I mean if I know $search is 3 words then I can do
$words = preg_split("/ /", $search);
So if you have used explode() then you can do a loop that goes through the array, for instanceif (eregi(".*words[0].*words[1].*words[2].*", 'possible result')) { ..... }
Even if I know how many words there are, everytime the number of words in $search can be different.
$searchwords=explode(' ', $search);
for ($x=0;$x<count($searchwords);$x++) {//build the search command OR build the query // i recommend to make it a query, so:
$WHERE.= ' AND textfield=LIKE '"%'.$searchwords[$x].'%"';
}
//now cut off the first ' AND ' $WHERE=substr($WHERE,4,strlen($WHERE);
now finish the query $query="SELECT title,text,ID FROM tablename ".$WHERE;
then proceed by doing the query and showing the results.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php