468,315 Members | 1,488 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

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|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.
Jul 16 '05 #1
1 1759
noone:
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" ?


Split the input into words and search for all the words :P

André Nęss
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Treetop | last post: by
5 posts views Thread by ritchie | last post: by
27 posts views Thread by ruel loehr | last post: by
3 posts views Thread by ash | last post: by
8 posts views Thread by intrepid_dw | last post: by
3 posts views Thread by inkexit | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.