For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2004 > Multiple search on a single text file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Multiple search on a single text file
Philippe Waterloos

2004-03-26, 11:12 pm

Hello

I want to use a search engine based on text files and I found this one:
http://php.warpedweb.net/

I want to search with multiples criteria with text box,checkbox and
radio button.

Basically I already have this code:

function s_search($query) {
// Searches for query in the index file.
// Multiple word search originally contributed by Matthew Furister
<matt@agtown.com>

$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;
}




with the form here:

function s_print_search_form($query) {
// Function to print the search form.
?>
<div align="center"><form method="post">
<h4>Search for:</h4>
<input type="text" name="query" value="<?php echo $query ?>">
<input type="checkbox" name="query" value="Training"> Training<br>

<br><input type="submit" value="Search">
</form></div>

In this example, the last criteria is taken but the first one is not.
I want to be able to have something like this:
search.php?query=phil&training

If you have any idea, I would be interested to hear it.

thanks.
--
Philippe Waterloos | Web applications | www.soleica.ca
<http://www.soleica.ca>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com