Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.