Posted: Sun Jun 11, 2006 9:51 pm
it still doesn't work any ideas?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Jcart has already told you why.Jcart wrote:... strtolower($badwords[$i]))) ...
I would assume that is causing the error, considering your applying an array to a string function. Secondly, you might want to reconsider your whole setup as the logic and maintainability of the code seems odd. We've recently had a thread about a bbcode class which you may find of interest.
Code: Select all
// Username Badword Blocker
$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>";
print_r($bword);
echo "<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;
}
}Code: Select all
// Username Badword Blocker
$username_bad_check = $username;
$username_bad_check = strtolower($username_bad_check);
$badwords = array();
$badwords[] = array('aSs', ' * ');
$badwords[] = array('badword', ' * ');
// Drops * from array
$badwords = array_map(create_function('$input', 'return array(reset($input));'), $badwords);
// Change all words to lowerchase
$bw_count = count($badwords);
for($c=0; $c<=$bw_count; $c++){
array_map('strtolower', $badwords["$c"]);
}
// Dunno if this works:
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>";
print_r($bword);
echo "<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;
}
}Web Browser wrote:Notice: Undefined index: 2 in /home/cmmvideo/public_html/myvirtuallife.com/Login/user.php on line 124
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/cmmvideo/public_html/myvirtuallife.com/Login/user.php on line 124
Notice: Array to string conversion in /home/cmmvideo/public_html/myvirtuallife.com/Login/user.php on line 131
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.
Your username can not contain the word: Array ( [0] => aSs )
*The term "Bad Word" refeers to a curse words, an explicit words, or any other inappropriate word, or word we find to be inappropriate.
Code: Select all
$badwords[] = array('aSs', ' * ');
$badwords[] = array('badword', ' * ');Code: Select all
$badwords = array_map(create_function('$input', 'return array(reset($input));'), $badwords);Code: Select all
<?php
$username = "bass fisherman";
// Strip weird characters
$username = preg_replace('/[^A-Z0-9_]/i', '', $username);
$username = substr($username, 0, 16);
// Username Badword Blocker
$badwords = array();
$badwords[] = array('aSs', ' * ');
$badwords[] = array('badword', ' * ');
// Drops * from array
$badwords = array_map("reset", $badwords);
$badwords = array_map("preg_quote", $badwords);
// Regular expression pattern
$pattern = '/(' . implode("|", $badwords) . ')/i';
if (preg_match($pattern, $username, $matches)) {
$match = $matches[1];
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: $match</b>";
echo "<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;
}
?>