Re: Help with an array
noone:
[color=blue]
> 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" ?[/color]
Split the input into words and search for all the words :P
André Næss
Help with an array
Collapse
This topic is closed.
X
X
-
Guest replied -
Help with an array
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|appl e|apples|pear|p ears|banana|ban anas|
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_d b]</h4>");
$pages_found = " ";
foreach ($search_data as $search_page) {
$page_arr = explode("|", $search_page);
$found_count = 0;
$qry_array = split('[, ]+',trim(strtolo wer($query)));
foreach ($qry_array as $qry) {
if (in_array($qry, $page_arr)) {
++$found_count;
$pages_found .= $page_arr[0] . " ";
}
}
if ($found_count == count($qry_arra y)) $result_arr[] = $page_arr[0];
}
return $result_arr;
}
thanks.
Tags: None
Leave a comment: