Hi
Can you help? I am trying to get a script work that was posted by ncbones a while back. It was for accessing the compare word from an sql database, I want to use and array or may be a text file.
The code:
//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 SQL
function filter($input){
$selectbadwords=mysql_query("SELECT * FROM badwords");
while($getbadwords=mysql_fetch_array($selectbadwords)){
$input=exefilter($getbadwords["word"],$input);
}
return $input;
}
//filter the string for each badword listed PHP ARRAY
function filterexp($input){
$files = "enbad.php";
include $files;
for($i = 0; $i < count($invalidwords); $i++) {
$input=exefilter($invalidwords[$i],$input);
}
return $input;
}
//////////////////////////////////
$output=filterexp($input)
ARRAY (not complete has at least 30 word):
$invalidwords = array (
"s**t","s888888e","p888k"
);
This does work in a fashion, but will not filter all the words that are in the array.