After doing some research I can't seem to find a solution to my problem. I have a list of bad words and I want to be able to see if a user left a comment with any of those words. I have tried different regular expressions with no success. BTW Im no regex guru.
Lets say I have the word $word = 'bi'
on my list. And a comment that says: $comment = he is bi
, using preg_match($pattern, $comment)
where parent has been: 1)$word#i
2)/\s+($word)/\s+/i
3)/\b($word)/\b/i
With this code:
if (preg_match($pattern, $commentdata['comment_content'])) {
echo 'spam';
}
else {
echo 'true'
}
I get:
1)spam
this is also the case for words linke combination
which I dont want to block
2)true
3)true
How can I make a pattern that only matches the word and not the word within?