Jump to content

badword script function non functional


CBaZ

Recommended Posts

the $blockwords are like so

$blockwords=array('word','word');

 

function has_bad_words($quote)
{
global $blockwords;

$split = preg_split("#\s+#", $post, -1, PREG_SPLIT_NO_EMPTY);

if (is_array($split))
{
	foreach ($split as $quote_word)
	{
		if (in_array($quote_word, $blockwords))
		{
			return true;
		}
	}
}

return false;
}

if (has_bad_words($quote_word))
{
echo "<BR><BR><p><center></center></p>";
                   echo "<li>Your Submission Encountered The Following Problem:<center><strong>$name, </strong>Left<strong> $quote_word
<br>..Spam Detected..</strong><br><font color=red>$ip</font> Banned</center></li>";
                   echo "<p><center></center></p>";
$date = date("d.m.Y  H:i:s");
$bp = fopen("banip/banip.txt", "a");
$domain = gethostbyaddr($_SERVER['REMOTE_ADDR']); 
$ip = $_SERVER['REMOTE_ADDR'];
$browser = getenv("HTTP_USER_AGENT"); 
fwrite($bp, "\n$ip,  $date,  $browser, $domain");
fclose($bp);
exit;
}

Link to comment
https://forums.phpfreaks.com/topic/68259-badword-script-function-non-functional/
Share on other sites

<?php
function has_bad_words($quote)
{
global $blockwords;

$split = preg_split("#\s+#", $quote, -1, PREG_SPLIT_NO_EMPTY);

if (is_array($split))
{
	foreach ($split as $quote_word)
	{
		if (in_array($quote_word, $blockwords))
		{
			return true;
		}
	}
}

return false;
}

?>

Looks like just a typo to me:

 

This line:

$split = preg_split("#\s+#", $post, -1, PREG_SPLIT_NO_EMPTY);

 

Should be:

 

$split = preg_split("#\s+#", $quote, -1, PREG_SPLIT_NO_EMPTY);

 

Of course, this function isn't going to help much if someone doens't put a space between their swear words.

 

darkfreaks : That wouldn't help. If you used that function, then it would only ever compare the first word in the string, because the function returns something after that first word.

<?php     
   $cast = 'Profanity, Profanity2, Profanity3'; // Naughty Sailor Talk 
   $st_str = trim($cast, ' '); // Trim white spaces  
   $strs = explode(',', $cast); // Explode into an array by delimiter 
   $content = 'What the Profanity is going on' //the text to apply it to. 
        
   for($i=0; $i<sizeof($strs); $i++)  
    {            
         $str = ' '.$strs[$i].' '; 
         $text = eregi_replace($str,' ',$text);  
     }  
?> 

Well, you could look into using regular expressions to search for your swear words - this would remove issues of capitalization and use of spaces before/after words, however, people will ALWAYS be able to beat the filters. You can't possibly block all possible variations on spelling and use of symbols that could be read by humans. You have to decide how important it is to block the words. Im pretty sure there are existing language filters out there. Perhaps you could have a look for one.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.