> hello all,
> this is continued from a previous post. i am still stuck, and really could
> use some help.
>
> basically, via a form, search words are submitted, i.e. "apple". it then
> searches through
> the contents of the index_file and sees if a match is found.
> if you searched for "apple orange", then a match for index1.html (listed
> below) would be
> returned.
>
> however, if you search for "apple pie", NO match is returned. even though,
> "apple" and "pie"
> are in the file, they are just not on the same line.
>
> can someone please look at the function and see if it is possible to make
> searches return matches
> if two or more words are entered, and they exist on different lines ?
>
> the contents of $GLOBALS[index_file]:
> [url]http://127.0.0.1/index1.html|apple|orange|banana|[/url]
> [url]http://127.0.0.1/index2.html|pie|[/url]
>
> we'll hardcode the variable:
> $query = "apple pie";
>
> the function:
> 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;
> }
>
> many thanks all.
>
>
Bookmarks