Search function

Hi all,
I’m pretty familiar with HTML, but at my workplace I’ve been asked to implement a search function on a webpage I manage. I don’t believe using Google would be a good option, as it’s an internal site.
The previous person managing the site had a section of the site that was searchable, so I attempted to copy the code from that and uploaded the PHP page onto our FTP client. It all seems to be working fine, except I need to figure out how to change searches to not be case sensitive. Right now, results are only coming up for perfect case matches. Would I do this in the index page or the php search results page, and how so? I could post the coding for either one if it’s needed.

Well, not sure how your data is being returned, sent or processed, although here is a couple of solutions…

your search data

[php]strtolower($search)

strtolower($data_being_searched)[/php]

Also look at this stuff:
http://php.net/manual/en/function.soundex.php
http://php.net/manual/en/function.similar-text.php
http://php.net/manual/en/function.levenshtein.php

If you are returning data from a DB, you can use LOWER

[php]select qt.*
from query_table qt
where LOWER(column_name) LIKE LOWER(’%vAlUe%’);[/php]

I believe it’s returning results from the directory. It’s also very strange because on the other portion of the site, the search is not case sensitive. It makes me wonder if something else is affecting it, as I haven’t changed any of the coding except to put it on this particular section.

This is from the front page:

[php]

[/php]

This is from the results page:

[php]<?php
$bResults = false;
$search = $_POST[‘search’];
$searchChunks = explode(" ", $search);
for($i = 0; $i < count($searchChunks); $i++)

foreach (glob("{/$searchChunks[$i].pdf,//$searchChunks[$i]*.pdf}", GLOB_BRACE) as $filename)
{
echo “<a href=”".$filename."">".$filename."

";
$bResults = true;
}

if (!$bResults)
{
printf(“No matches for search criteria ‘%s’.\n”, $search);
}
?>[/php]

I figured it out! I don’t know how I accidentally deleted a line between the two formats but gosh, that caused a lot of grief.

I also have one more question: Is there any way I can get the search function to search outside of the directory? As in, we have some files that are uploaded to our server through the FTP client, and it only yields those results. However, we also have files that are online through Google docs and other means. Is there a way I can make those show up in the results or would I have to rebuild the entire search?

I guess I have another question too. I thought I fixed the caps problem, but it seems that that script just auto-capitalizes the search query, which is great for most of the files we have uploaded, but we still have some that are lowercase or in all caps. How can I fix it so caps just doesn’t matter in yielding results, and how can I make it search the entire site?

Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service