Jump to content

How to stop spam (several characters in a row no spaces)


virtuexru

Recommended Posts

<pre>
<?php
$tests = array(
	'a',
	'aaa',
	'aaaaaa',
	'aaaaaaaaa',
	'aaaaaaaaaaaa',
	'aaaaaaaaaaaaaaa',
	'b aa',
	'bbb aaaaaa',
	'bbbbbb aaaaaaaaa',
	'bbbbbbbbb aaaaaaaaaaaa'
);
foreach ($tests as $test) {
	echo $test, '<br>  ';
	echo preg_match('/(.)(?=\1{9})/', $test) ? 'Spam' : 'Not Spam';
	echo '<hr>';
}
?>
</pre>

    function spamcheck($text,$nr=10)
   {
       $spamtext=explode(" ",trim($text));
       $newtext=array();
       foreach($spamtext as $k=>$txt)
       {
           if (strlen($txt)>$nr)
           {
               $txt=wordwrap($txt, $nr, "-", 1);
           }
           $newtext[]=$txt;
       }
       return implode(" ",$newtext);
   } 

 

So..

 

$spam = 'Spaaaaaaaaaaaaaaaam';
spamtext($spam);

 

Would Return ->

 

"Spaaaaaaa-

aaaaaaaam"

 

Just trying to help :) ($nr is how many characters you want it to detect)

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.