I need to check if a string contains any one of the banned words. My requirements are:
- Case insensitive which is why I used
stripos()
- Word should be separated by spaces, for example if banned word is "poker", "poker game" or "game poker match" should come under banned string and "trainpokering great" should come under good string.
I have tried something like below
$string = "poker park is great";
if (stripos($string, 'poker||casino') === false)
{
echo "banned words found";
}
else
{
echo $string;
}
if (preg_match("/\b(poker|casino)\b/i", $string))
) just works for all your use cases... :-) For example, "poker", "poker game" or "game poker match" are marked as banned, and "trainpokering great" is marked as good... Why do you say it doesn't?