I'm not so good at regex..
Looking for a way to trim the end of a string, if the end is:
A space followed by ONE character (can be any character)
Is preg_replace() the thing for that, or is there an easier and faster way?
The trimming will only happen once in the page
For just a space do this. And yes preg_replace is the way to go.
$string = preg_replace('/ .$/', '', $string);
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