Jump to content

Recommended Posts

I recently found this little script to help people making topics or posts with

 

"WWWWWWWWWWWWWWWWWWWWWWWWWWWWW"

 

OR "XX LETER HERE XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

 

Here it is:

 

function FindInstances($inputString)
{
    $enter = 0;
    $data = strtolower ($inputString);
    foreach (count_chars ($data, 1) as $i => $val)
        {
            if ($enter == 1)
            {
                $enter = 0;
                continue;
            }
            if (chr ($i) == "\n")
            {
                //echo "There are $val instance(s) of \" Enter \" in the string.\n";
                $enter = 1;
            }
            else
            {
                //echo "  There are $val instance(s) of \"" , chr ($i) , "\" in the string.\n";
			$cletter =''.chr($i).'';


		if ($cletter == 'w' AND $val >= 5){
		message("You cannot have 5 W's in your member title...");
		}if ($cletter == 'o' AND $val >= 5){
		message("You cannot have 5 o's in your member title...");
		}if ($cletter == 'q' AND $val >= 5){
		message("You cannot have 5 o's in your member title...");
		}if ($cletter == 'm' AND $val >= 5){
		message("You cannot have 5 o's in your member title...");
		}if ($cletter == 'g' AND $val >= 5){
		message("You cannot have 5 o's in your member title...");
		}if ($cletter == 'c' AND $val >= 5){
		message("You cannot have 5 o's in your member title...");
		}




            }
        }
}

 

anyone know how to short this baby down so it works for all letters of the alphabet?

Link to comment
https://forums.phpfreaks.com/topic/266345-good-script-to-block-spam-letters/
Share on other sites

  • 2 weeks later...

Changed it a little, you should get the idea.

 

<?php
function FindInstances($inputString)
{
$chr_array = range('a','z');
    $enter = 0;
    $data = strtolower(trim($inputString));
    foreach (count_chars ($data, 1) as $i => $val)
        {
            if ($enter == 1)
            {
                $enter = 0;
                continue;
            }
            if (chr ($i) == "\n")
            {
                //echo "There are $val instance(s) of \" Enter \" in the string.\n";
                $enter = 1;
            }
            else
            {
                //echo "  There are $val instance(s) of \"" , chr ($i) , "\" in the string.\n";
			$cletter =''.chr($i).'';


		if (in_array($cletter,$chr_array) AND $val >= 5){
		$chr_check = TRUE;
		}

            }
        }
        
if($chr_check == TRUE){
echo "You can't have 5+ the same letter's in your member title...";
} else {
return $inputString;
}        
    
}

//examples

$text = "writing this sample cccc";
$text2 = "writing this sample ffffffffff";
$text3 = "membername";
$text4 = "a zzzzzzzzzzzzzzzzz";

echo FindInstances($text)."<br />";
echo FindInstances($text2)."<br />";
echo FindInstances($text3)."<br />";
echo FindInstances($text4)."<br />";

?>

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.