Page 1 of 1

Badword Array Replacement [SOLVED]

Posted: Thu Jun 01, 2006 11:00 am
by tecktalkcm0391
Can someone help me with this. I want the following PHP code to look at the variable $username_bad_check which is equal to the $username (in this case 'ass12345'). If it finds any of the words in the $badwords array. Then it displays the message.

Code: Select all

<?php

$username = 'ass12345';
$username_bad_check = $username;
$username_bad_check = strtolower($username_bad_check);
$username_bad_check = " ".$username_bad_check." ";
    
// Array, Badword, Goodword
// Goodword is not used.
$badwords = array();

    $badwords[] = array('ass', ' * ');

if($username_bad_check == $badwords){
	echo "OH NO YOU DIDN\'T. We have found a bad word in your username\! You may have put something bad in by mistake, but remember if you use bad words\* on our site.<br><br><Br>*The term \"Bad Word\" refeers to a curse words, an explicit words, or any other inappropriate word, or word we find to be inappropriate.";
    }

?>

Posted: Thu Jun 01, 2006 1:47 pm
by Jade
Personally I'd use a foreach loop to check and see if any of the words in your bad words array are found in the name itself.
For instance...

Code: Select all

foreach ($badwords as $word)
{
      if (strstr($username, $word))
          echo "Your username cannot contain the word " . $word;
}
You get the idea. Basically you go through the entire array and see if any of those words are contained in the user name.
Hope this helps,

Jade