Say I have the following:
$str = "1AAABBCCCDDDDDDD";
How can I remove all the duplicate characters in the string? So it would look like this?
$result = "1ABCD";
All you need is count_chars()
:
$result = count_chars( $str, 3);
With the second parameter $mode
set to 3
, count_chars()
will output:
a string containing all unique characters
You can see from this demo that this produces:
1ABCD
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