View Full Version : Find a set of words in a string, not exactly regex-able?

02-12-2010, 02:51 PM
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!

02-12-2010, 03:54 PM
$string = 'los t ho rse .co m';
$string = strtolower(preg_replace('/[^a-z\.]+/i', '', $string));
if(strpos($string, 'losthorse.com') !== false) {
// Spam text found
// 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 .