It seems like an easy problem to solve, but It's not as easy as it seems. I have this string in PHP:
////%postname%/
This is a URL and I never want more than one slash in a row. I never want to remove the slashes completely.
This is how it should look like:
/%postname%/
Because the structure could look different I need a clever preg replace regexp, I think. It need to work with URLS like this:
////%postname%//mytest/test///testing
which should be converted to this:
/%postname%/mytest/test/testing
Late but all these methods will remove
http://
slashes too, but this.Try:
that's using str_replace
My solution:
Here you go:
Or:
Or even:
A simple
str_replace()
will also do the trick (if there are no more than two consecutive slashes):