I have a string which looks like this:
something-------another--thing
//^^^^^^^ ^^
I want to replace the multiple dashes with a single one.
So the expected output would be:
something-another-thing
//^ ^
I tried to use str_replace()
, but I have to write the code again for every possible amount of dashes. So how can I replace any amount of dashes with a single one?
For Rizier:
Tried:
$mystring = "something-------another--thing";
str_replace("--", "-", $mystring);
str_replace("---", "-", $mystring);
str_replace("----", "-", $mystring);
str_replace("-----", "-", $mystring);
str_replace("------", "-", $mystring);
str_replace("-------", "-", $mystring);
str_replace("--------", "-", $mystring);
str_replace("---------", "-", $mystring);
etc...
But the string could have 10000 of lines between two words.