Page 2 of 3

Posted: Sun Jun 11, 2006 9:51 pm
by tecktalkcm0391
it still doesn't work any ideas?

Posted: Sun Jun 11, 2006 11:00 pm
by aerodromoi
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.
Jcart has already told you why.

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

Posted: Sun Jun 11, 2006 11:03 pm
by tecktalkcm0391
wow I read the manual totally wrong. What I was trying to do is have the data in the array being changed all to lowercase, like if the array had Bad it would change it to bad...

Can you even do this... if so how?!?!?!?!?

Posted: Sun Jun 11, 2006 11:20 pm
by Christopher
If you browse through the Array Function in the PHP Manual I am sure you will find a function that will do what you want -- plus there is plenty of example code in the manual.

Posted: Tue Jun 20, 2006 11:16 pm
by tecktalkcm0391
ok I still cant get this to work if I try with $username = yowhatsup it doesn't work!

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;
    } 
}
Any input?

Posted: Tue Jun 20, 2006 11:20 pm
by tecktalkcm0391
any mod can tell me the code to make words smurf?

Posted: Tue Jun 20, 2006 11:32 pm
by John Cartwright
array_map() in combination with strtolower().. as abortint suggested you look for :wink:

Posted: Tue Jun 20, 2006 11:41 pm
by tecktalkcm0391
this right: array_map('strtolower', $badwords);

Posted: Tue Jun 20, 2006 11:47 pm
by tecktalkcm0391
this is what I have as of now...

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;
    } 
}
I get this when I run it:
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.

Posted: Tue Jun 20, 2006 11:47 pm
by John Cartwright
before posting, triple check which variables you are using :? fyi, you shouldn't be using str_replace.. cough str_ireplace() for case insensitive string replaces.

Posted: Tue Jun 20, 2006 11:53 pm
by tecktalkcm0391
so if i use str_ireplace i wont need to worry about the upper/lower case stuff in the array or username. :P :P :P

Posted: Tue Jun 20, 2006 11:54 pm
by tecktalkcm0391
nevermind. I have PHP 4.

UPDATE: I just ran phpinfo(); and my hosts updated my php version 5 :D :D :D

Posted: Tue Jun 20, 2006 11:58 pm
by Robert Plank
What's the point of the asterisks?

Code: Select all

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

Posted: Tue Jun 20, 2006 11:59 pm
by tecktalkcm0391
its because I am using the same array as my badword filter, and I don't really feel like deleting them. Thats what

Code: Select all

$badwords = array_map(create_function('$input', 'return array(reset($input));'), $badwords);
does for me

Posted: Wed Jun 21, 2006 12:03 am
by Robert Plank
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;
}

?>