Jump to content

Check string for blacklisted words?


SaMike

Recommended Posts

Im creating login system to my webpage. On registering i'd wish to check if username got any part blacklisted.

So if i blacklist word 'shit' and user tries 'youreshitlol' it would return error because PART of it is blacklisted.

 

How could i achieve this (with multiple blacklisted words)?

Link to comment
https://forums.phpfreaks.com/topic/198042-check-string-for-blacklisted-words/
Share on other sites

$blackList = array(
    'shit',
    'crap'
);

$valid = true;
foreach($blackList as $blackItem)
{
    if(strpos($str, $blackItem) !== false)
    {
         valid = false;
         break;
    }
}

if(!$valid)
{
    // Did not validate
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.