2012-07-06 70 views
0

何时存在字符数量要求。有些用户可能会用重复的垃圾文本填写剩余的配额。我想设置允许的重复次数。如何检查重复文本的用户输入

+0

我恨字量的要求..你的用户就写“那“出于某种原因的文字量可能?任何您要创建的伪检查仍然会很容易闪避并让您(已经很沮丧的)用户多一点烦恼 – kali 2012-07-06 15:56:23

回答

1
$input = "this is a test to see if there are repeats in this sentence blah blah blah as these three here"; 


    if(check_input($input, 3) === false) 
     var_dump("No repeat found"); 
    else 
     var_dump("Repeat found"); 


    function check_input($input, $maximum_repeats){ 
     $repeat_found = false; 

     for($i = 0; $i < strlen($input) && $repeat_found == false; $i++){ 

      for($k = 0; $k < strlen($input) && $repeat_found == false; $k++){ 
       $test = substr($input, $i, $k); 

       if(strlen($test) > 0){ 
        if(find_repeat($test, $input, $maximum_repeats) === true){ 
         $repeat_found = true; 
        } 
       } 
      } 
     } 

     return $repeat_found; 
    } 

    function find_repeat($target, $input, $amount){ 
     $needle = ""; 

     for($i = 0; $i < $amount; $i++) 
      $needle .= $target; 

     return strpos($input, $needle) !== false; 
    } 

此功能会响“等等等等等等”和其他的例子,如

确定真的......