473,508 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2051
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1936
by: Treetop | last post by:
I am creating a calendar with JavaScript. I want to be able to put date and time in an array and have a calendar display properly with 7 columns. I am stuck at this point. Any help would be...
3
1927
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
7
3570
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
2190
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
27
2311
by: ruel loehr | last post by:
Hey guys, I am looking for some insight: Given two sorted arrays of integers A and B, where array B has enough extra room in it to hold the contents of both A and B. Merge array A and B...
3
3802
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
8
10685
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
3720
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
4
6277
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.