Replace multiple occurrences of same symbol using preg_replace?

Viewed 10268

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";
5 Answers
Related