Hi, I have the following bad word filter function but for some reason it is classing the word "test" as a bad word. In my database table I only have one word that is similar to this and that is "testa". My site is in 8 languages so often a bad word is similar to a god word in a different language but as this is not exactly the same, I can't work out why it is classing it as bad.
Any suggestions would be great.
Peter
<?php
function ReplaceBadWords( $str )
{
$words = getbadwords();
foreach ( $words as $badword => $goodword )
if ( preg_match( $expr = '~(^|[^a-z0-9]?)(' . $badword . '?)($|[^a-z0-9])~iU', $str ) )
$str = preg_replace( $expr, "\\1{$goodword}\\3", $str );
return $str;
}
function getbadwords()
{
$sql = "select word from word_filter";
$words = runsql( $sql );
foreach( $words AS $w ) {
$bwords[$w["word"]] = '******';
}
return $bwords;
}
?>
And function runsql( $sql ) is
function runsql( $sql )
{
$res = mysql_query( $sql ) or die( mysql_error() );
$out = array();
if ( mysql_num_rows( $res ) > 0 ) {
while ( $a = mysql_fetch_assoc( $res ) ) {
$out[] = $a;
}
}
return $out;
}