SaMike Posted April 8, 2010 Share Posted April 8, 2010 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)? Quote Link to comment https://forums.phpfreaks.com/topic/198042-check-string-for-blacklisted-words/ Share on other sites More sharing options...
Alex Posted April 8, 2010 Share Posted April 8, 2010 $blackList = array( 'shit', 'crap' ); $valid = true; foreach($blackList as $blackItem) { if(strpos($str, $blackItem) !== false) { valid = false; break; } } if(!$valid) { // Did not validate } Quote Link to comment https://forums.phpfreaks.com/topic/198042-check-string-for-blacklisted-words/#findComment-1039150 Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 Another way... $badwords = "badword1|badword2|badword3|badword4|badword5|badword6"; $subject = 'my name is badword4'; if (preg_match ("/$badwords/", $subject)) { // bad word found } else { // not found } Quote Link to comment https://forums.phpfreaks.com/topic/198042-check-string-for-blacklisted-words/#findComment-1039152 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.