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 2 of 2
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Find a set of words in a string, not exactly regex-able?

    I have a question. I have a set of words that i need to find in a string. The word is losthorse.com. I can successfully find losthorse.com but I want to be able to find lost horse.com or lost horse .com or many other combinations of changing spacing between the words.

    Is there an automated way I could do this, or would I simply have to program in searches for each of these weird ways of displaying the string?

    The reason i'm doing this is there is a spammer I am trying to stop, who is evading my techniques by changing the spaces between the words to get around my filters.

    Thank you!

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    $string 'los t ho rse .co m';
    $string strtolower(preg_replace('/[^a-z\.]+/i'''$string));
    if(
    strpos($string'losthorse.com') !== false) {
        
    // Spam text found
    }else{
        
    // Spam text not found

    untested, but should work. What this does is remove all spaces from the text and change the case to lower case. Then it searches for the text in the new text which has no spaces in it now (or any other characters other than a-z and .
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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