Guest User

Untitled

a guest
Nov 23rd, 2012
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function notCharsXTimesInARow($string, $amount = 4)
  4. {
  5.     $lastChar = '';
  6.     $counter = 0;
  7.     for ($i = 0; $i < strlen($string); $i++) {
  8.         if ($string[$i] === $lastChar) {
  9.             $counter++;
  10.         } else {
  11.             $counter = 0;
  12.         }
  13.  
  14.         if ($counter == $amount - 1) {
  15.             return false;
  16.         }
  17.         $lastChar = $string[$i];
  18.     }
  19.     return true;
  20. }
  21.  
  22.  
  23. $test = array(
  24.     'Florian'    => true,
  25.     'qwerty'     => true,
  26.     'asasasasas' => true,
  27.     'aaaa'       => false,
  28.     'aaasssdddd' => false,
  29.     'aaasssddd' => false
  30. );
  31.  
  32. foreach ($test as $k => $t) {
  33.     if (notCharsXTimesInARow($k) !== $t) {
  34.         echo "$k ist falsch.\n";
  35.     }
  36. }
RAW Paste Data