I have a string where I want to remove all the whitespace around a certain character using preg_replace. In my case this character is /.
For example:
first part / second part would become first part/second part
Or let’s say that character is : now:
first part : second part would become first part:second part
I couldn’t find an example on how to do this… Thanks!
Explanation:
\s*means any amount (*) of whitespace (\s)[\/:]is either a/or a:. If you want another character, just add it here.$1meaning that if it matches a:then the $1 will mean:.