laserlight- why- because > takes less space than < ?
for those in the future searching for the word "filter", here is my PHP function for filtering user input... create a table in MySQL with a list of words to filter (don't worry about different cases, or people doing simple things such as r.u.d.e)
Note that this will not remove all rude words, only those specified in the database, and will not remove those with a different symbol between each leter (e.g. "r.u#d.e", given there are 8 different possible character separators, this would require a for-loop to run 88 times- which would take a rather long time- and is perhaps overkill!) From past experience, most people just type the words, they are not intending to fool the system- except where proving my script doesn't work :-) Enjoy
//following functions attempt to filter out swearwords
//these cannot necessarily remove all swearwords, there are always workarounds, but I've done my best!
//insensitive search and replace- avoids people doing things like BaDwOrD
function stri_replace( $find, $replace, $string ){
$parts = explode( strtolower($find), strtolower($string) );
$pos = 0;
foreach( $parts as $key=>$part ){
$parts[ $key ] = substr($string, $pos, strlen($part));
$pos += strlen($part) + strlen($find);
}
return( join( $replace, $parts ) );
}
//insert a chracter between each letter of a string, this enables us to filter out words like i.d.i.o.t
function insertcharacter($character,$input){
for ($i=0; $i<strlen($input); $i++){
$return.=$input[$i]."$character";
}
if ($character != ''){
$return=substr($return,0,strlen($return)-1);
}
return $return;
}
//do the replace, given a badword
function exefilter($badword,$contents){
//characters between each letter of a swearword that mean that they are still swearwords
$characters=array('','@',' ','.','#','^',' ',' . ');
foreach($characters as $character){
$characteredword=insertcharacter($character,$badword);
$contents=stri_replace($characteredword,str_pad($badword[0],strlen($badword),"*",STR_PAD_RIGHT),$contents);
}
return $contents;
}
//filter the string for each badword listed
function filter($input){
$selectbadwords=mysql_query("SELECT * FROM badwords");
while($getbadwords=mysql_fetch_array($selectbadwords)){
$input=exefilter($getbadwords["word"],$input);
}
return $input;
}
So, to filer userinput just do
$output=filter($input)