How to remove unnecessary spaces in string with PHP?
To remove unnecessary spaces in your aplication string, simply use PHP's native trim function. This function returns a string with spaces removed from the beginning and end. To remove trailing-only spaces, simply use rtrim function and, to remove leading-only spaces, simply use ltrim function.