Badword Seach in String or Variable
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
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.
Just a hint - you're trying to set a string to lowercase - so it has to be $badwords[$i][0],
not just $badwords[$i]. Btw: Why do you want to change the keys of the array? They are integers!
There is no such thing as an uppercase or lowercase number
aerodromoi
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
ok I still cant get this to work if I try with $username = yowhatsup it doesn't work!
Any input?
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;
}
}
Last edited by tecktalkcm0391 on Tue Jun 20, 2006 11:20 pm, edited 1 time in total.
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
this is what I have as of now...
I get this when I run it:
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
-
Robert Plank
- Forum Contributor
- Posts: 110
- Joined: Sun Dec 26, 2004 9:04 pm
- Contact:
What's the point of the asterisks?
Code: Select all
$badwords[] = array('aSs', ' * ');
$badwords[] = array('badword', ' * ');- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
its because I am using the same array as my badword filter, and I don't really feel like deleting them. Thats what does for me
Code: Select all
$badwords = array_map(create_function('$input', 'return array(reset($input));'), $badwords);-
Robert Plank
- Forum Contributor
- Posts: 110
- Joined: Sun Dec 26, 2004 9:04 pm
- Contact:
Oh ok. Well here you go
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;
}
?>