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
https://forums.phpfreaks.com/topic/19372-split-keyword-search-into-array/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.