Let's say I have a string like this:
$string = "hello---world";
How would I go about replacing the --- with a single hyphen? The string could easily look like this instead:
$string = "hello--world----what-up";
The desired result should be:
$string = "hello-world-what-up";
$string = preg_replace('/-{2,}/','-',$string);
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