I just wanted to check this code was valid for what I am trying to do (replaces tab(s) or multiple spaces with one space.
preg_replace('/\t+|\s{2,}/', ' ', $street);
However what if it found a tab AND a space together, then wouldn't we end up with two spaces then? The original space & the new one the tab got replaced with.
How can I change it so any spaces in the string always end up only being the one space?
As \s
will match both tabs and spaces (as well as other forms of white-space), this itself should do the trick to replace any amount of consecutive white-space with a single space:
preg_replace('/\s+/', ' ', $street);
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