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)? 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 } 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 } 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
Archived
This topic is now archived and is closed to further replies.