I need to modify a series of strings containing e.g.
to become e.g.:
_ 123abc _
So each last underscore on the front of the middle needs a space if it has one and on the end of the middle bit a space before the underscore if an underscore is there. If there is no underscore then no space is added.
I can do this using an inelegant for loop although there must be a better way.
I tried using preg_replace ereg_replace although the syntax isn't documented well enough for me to use it.