Jump to content

Split Keyword Search Into Array?


barkster

Recommended Posts

I'm wanting to split my search keywords on my site into seperate words to increase likelyhood of hit.  Does anyone have an example on how to do this or maybe a script that will do something similar.  For instance if you search "car blue chevy" that it will return results for a "blue chevy car".

Thanks
Link to comment
Share on other sites

try
[code]
<?php

$whereclause = '';
$where = array();
if ($_GET['keywords']) {
    $keywords = explode(' ', $_GET['keywords']);
    foreach ($keywords as $kw) {
        $kw = get_magic_quotes_gpc() ? trim($kw) : addslashes(trim($kw));
        $where[] = "(description LIKE '%$kw%')";
    }
    $whereclause = "\nWHERE " . join (" \nAND ", $where);
}
$sql = "SELECT id, description FROM mytable $whereclause";
echo '<pre>',$sql,'</pre>';
?>
<FORM>
<input type="text" name="keywords" size="40">
<input type="submit" name="submit" value="Search">
</FORM>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.