...

View Full Version : Effecient string cleanup with blacklist



mwookie
08-29-2007, 03:57 PM
Can someone tell me the most effecient way to remove blacklisted words from a string? I am working on my stock image search engine (http://www.imagetrail.net) . I have noticed that a lot of people put in words like "image" and "photo" into their searches, which reduces the results, because they are all images / photos and most photographers don't use this as a keyword.

SOoo.. Is is best to explode() the string and do an in_array() comparison against an array of "bad words" or maybe use a regular expression to pull out the words?

Any ideas or (even better) code tidbits would be so helpful, thanks.

_________________________
"Insanity is hereditary - you get it from your children." Sam Levenson
Company (http://www.emblemsoftware.com) Projects ($1 Images for your website (http://www.imagetrail.net/search_background_photos.php) New Mexico Resource Directory (http://www.newmexicodirect.net))

aedrin
08-29-2007, 04:42 PM
How about str_replace() with an array of bad words, replacing them with nothing?



$bad = array('photo', 'picture');
$searchQuery = str_replace($bad, '', $searchQuery);

mwookie
08-29-2007, 04:45 PM
How about str_replace() with an array of bad words, replacing them with nothing?



$bad = array('photo', 'picture');
$searchQuery = str_replace($bad, '', $searchQuery);


I din't know str_replace could accept an array, you learn something new every day! Thanks.

aedrin
08-29-2007, 04:52 PM
http://us3.php.net/str_replace

The PHP manual has all the information that you need.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum