如何检查重复文本的用户输入
答
$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;
}
此功能会响“等等等等等等”和其他的例子,如
确定真的......
我恨字量的要求..你的用户就写“那“出于某种原因的文字量可能?任何您要创建的伪检查仍然会很容易闪避并让您(已经很沮丧的)用户多一点烦恼 – kali 2012-07-06 15:56:23