$wordlist = array(" the ", " at ", " of "," and "." you "," me "," i "); $search = trim(mysql_real_escape_string(strtolower($_POST["search"]))); foreach($wordlist as $word) { $search = str_replace($word, "", $search); } $type = trim(mysql_real_escape_string($_POST["type"])); $term = preg_split("/[,\s]+/", $search);
Database Searching Word Filter
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Database Searching Word Filter
I have developed a database searching script from the tutorial on this site. This is the technique I use to filter out the short words. There is a space at the beginning and end of every word in the array because otherwise it would have filtered out where it matched in the middle of words, so I'd end up with "cody" instead of the word "comedy" in the term array
Re: Database Searching Word Filter
Looks good
You could also do this, which is basically the same but you don't need to manually define a list of short words to ignore.
You could also do this, which is basically the same but you don't need to manually define a list of short words to ignore.
$search = trim(mysql_real_escape_string(strtolower($_POST["search"]))); $terms = preg_split("/[,\s]+/", $search); foreach ($terms as $key => $term){ if (strlen($term) < 4){ unset($terms[$key]); } }