So I have $comment but they decided to say "aaaaaaaaaaaaaa" or any other string of characters that is repeated more than 3 times. How do I remove those words from the string? It would be ideal to check if any characters are repeated more than 3 times and replace those characters with a blank space, or something like that Any ideas?
$string = 'aabbccaaaaaddee'; $new_string = ''; $starting_char = 0; while (strlen($string) > 0 && $starting_char < strlen($string)) { $blah = preg_match('/[A-z]{3,}/', $string, $matches); $letter = $matches[0][$starting_char]; $new_string .= $letter; $regex = '/' . $letter . '{3,}/'; $string = preg_replace($regex, $letter, $string); $starting_char++; } echo $new_string; PHP: