I have a site where users can put in a description about themselves.
Most users write something appropriate but some just copy/paste the same text a number of times (to
You could use a regex, like this:
if (preg_match('/(.{10,})\\1{2,}/', $theText)) {
echo "The string is repeated.";
}
Explanation:
(.{10,})
looks for and captures a string that is at least 10 characters long\\1{2,}
looks for the first string at least 2 more timesPossible tweaks to suit your needs:
10
to a higher or lower number to match longer or shorter repeated strings. I just used 10
as an example.love and peace love and peace
), delete the {2,}
. If you want to catch a higher number of repetitions, increase the 2
.,
in {2,}
.