Monkuar Posted July 27, 2012 Share Posted July 27, 2012 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 More sharing options...
QuickOldCar Posted August 5, 2012 Share Posted August 5, 2012 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 />"; ?> Link to comment https://forums.phpfreaks.com/topic/266345-good-script-to-block-spam-letters/#findComment-1366994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.