Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2007
    Location
    NM. USA
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Effecient string cleanup with blacklist

    Can someone tell me the most effecient way to remove blacklisted words from a string? I am working on my stock image search engine . 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 – Projects ($1 Images for your website New Mexico Resource Directory)

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    How about str_replace() with an array of bad words, replacing them with nothing?

    PHP Code:
    $bad = array('photo''picture');
    $searchQuery str_replace($bad''$searchQuery); 

  • Users who have thanked aedrin for this post:

    mwookie (08-29-2007)

  • #3
    New Coder
    Join Date
    Feb 2007
    Location
    NM. USA
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by aedrin View Post
    How about str_replace() with an array of bad words, replacing them with nothing?

    PHP Code:
    $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.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    http://us3.php.net/str_replace

    The PHP manual has all the information that you need.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •