I have strings like this one:
$str = 'This -----is a bbbb test';
How can I remove all duplicate characters if it occurs more than 3 times?
So, for example, the string above must look as follows:
'This is a test';
You can do this using regular expressions and preg_replace():
$new_str = preg_replace('/(.)\1{3,}/', '', $str);
$t = preg_replace('/(\S)\1{3,}/', '', $t);
Every non-space longer than 3 chars will be replaced with nothing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With