preg_match to find weird words by spammer

Viewed 51

anyone can help me dealing with a spammer that keeps finding ways to go around my spam filter? Basically his domain name is something like abcdef.com and he uses stuff like:

a#b#c#d#e#f.com

a b c d e f.com

a$b$c$d$e$f.com

this is running for a whole month, at first I thought that people would not even try to copy and paste his url but he doesnt give up, so I think he's making profit with it.

I'm trying this:

if (!preg_match("/(?<=A)(.*)(?=B)(.*)(?=C)(.*)(?=D)(.*)(?=E)(.*)(?=F)/i", "$textfield"))

it works but it also works against everyone that uses all those 6 characters in any order. thanks in advance

1 Answers

You can try sanitize the text first by strip out everything other than alpha/num.

$spamDomain = preg_replace("/[^A-Za-z0-9]/", "", $textfield);

After that check if it match the domain

if (strpos($spamDomain, 'abcdef') !== false) {
    return false;
}
Related