0

文字数の要件がある場合。一部のユーザーは、残りのクォータに繰り返しのガベージテキストを入力する場合があります。繰り返し回数を設定したいのですが。

4

1 に答える 1

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;
    }

この関数は、「何とか何とか何とか」やその他の例に当てはまります。

わかった...

于 2012-07-06T15:21:34.867 に答える