PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Is there a way to have PHP add symbols between the letters in each array where the badword is? I am trying to do this so that I don't have to keep entering the same word and adding marks between them. This badword filter is for a website for kids, so I need everything to be blocked. And you know how tricky some kids can get.
Last edited by tecktalkcm0391 on Tue Jun 06, 2006 10:45 pm, edited 2 times in total.
Can someone tell me how to fix this so that it returns the badword not 'array'. I would also like to change it if possible so it does the check like this:
$username_bad_check = '12bad74words';
$username_bad_check = strtolower($username_bad_check);
$badwords = array();
$badwords[] = array('bad', ' * ');
$badwords[] = array('words', ' * ');
array_change_key_case($badwords,CASE_LOWER);
/*$username_bad_check = implode("\r\n", $username_bad_check); */
foreach ($badwords as $bword)
{
if (str_replace($username_bad_check, $badword, $bword)){
echo "OH NO YOU DID'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><b>Your username can not contain the word </b>" . $bword . "<br><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." ;
exit;
}
}
So if anyone could help me fix this it would be appreciated. Also I got an error that it couldn't convert array to string, it only came up once though. anybody know why it would have come up?
$username_bad_check = '12bad74words';
$username_bad_check = strtolower($username_bad_check);
$badwords = array();
///HERE IS YOUR PROBLEM
$badwords[] = array('bad', ' * ');
$badwords[] = array('words', ' * ');
array_change_key_case($badwords,CASE_LOWER);
/*$username_bad_check = implode("\r\n", $username_bad_check); */
foreach ($badwords as $bword)
{
if (str_replace($username_bad_check, $badword, $bword)){
//This should echo out your "badword"
echo $bword[0];
echo "OH NO YOU DID'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><b>Your username can not contain the word </b>" . $bword . "<br><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." ;
exit;
}
}
$username = 'bad12434word';
$username_bad_check = $username;
$username_bad_check = strtolower($username_bad_check);
$badwords = array();
$badwords[] = array('bad', ' * ');
$badwords[] = array('word', ' * ');
array_change_key_case($badwords,CASE_LOWER);
/*$username_bad_check = implode("\r\n", $username_bad_check); */
foreach ($badwords as $bword)
{
if (str_replace($username_bad_check, $badwords, $bword)){
echo "OH NO YOU DID'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><b>Your username can not contain the word: </b>" . $bword[0] . "<br><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." ;
exit;
}
}
And I am getting an error that say:
Notice: Array to string conversion in /home/cmmvideo/public_html/myvirtuallife.com/Login/user.php on line 123
You aren't using str_replace() correctly, it should be str_replace('word(s) to replace', 'word(s) to replace them with', 'string with word(s) that need(s) replacing). Although, I'm not even sure why you are using str_replace() here at all as you never actually test for the bad words, it will give them the error message no matter what. Try the following instead:
$username = 'bdad12434word';
$username_bad_check = $username;
$username_bad_check = strtolower($username_bad_check);
// you only need an array of the words you are checking for
$badwords = array('bad', 'word');
foreach ($badwords as $bword) {
if (strstr($username_bad_check, $bword)) {
echo "OH NO YOU DON'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><b>Your username can not contain the word: </b>" . $bword . "<br><br><br><Br>*The term \"Bad Word\" refers to a curse words, an explicit words, or any other inappropriate word, or word we find to be inappropriate.";
break;
}
}
Although, I'm not even sure why you are using str_replace() here at all as you never actually test for the bad words, it will give them the error message no matter what.
OK, well then what should I use, and how can I get the error message to go away !