hello all.
this is a function that i am using which compares values submitted via form,
to an index file, and if there
is a match, it returns the name of the file that matched.
the function supports multiple "keywords" entered in the form, for example
"apple pie". however, it
fails if it doesn't match the complete "apple pie", even though "apple"
matches fine when entered in
all by itself.
is there a way to update/mod this function so if at least 1 match is found
when multiple words are submitted
that it will still return a "match" ?
btw, the index file that it searches is formatted as such:
(a line from the index file)
http://127.0.0.1/fruit.html|apple|apples|pear|pears|banana|bananas|
function s_search($query) {
$query = trim(strtolower(c_strip_chars($query)));
$search_data = @file($GLOBALS[index_file]) or die("<h4
align=\"center\">$GLOBALS[err_no_search_db]</h4>");
$pages_found = " ";
foreach ($search_data as $search_page) {
$page_arr = explode("|", $search_page);
$found_count = 0;
$qry_array = split('[, ]+',trim(strtolower($query)));
foreach ($qry_array as $qry) {
if (in_array($qry, $page_arr)) {
++$found_count;
$pages_found .= $page_arr[0] . " ";
}
}
if ($found_count == count($qry_array)) $result_arr[] = $page_arr[0];
}
return $result_arr;
}
thanks.