PHP trim() removes whitespace from the beginning and end of a string. It does not remove spaces during a string. The usage of trim() is very simple.
This example shows trim() best
$new_string = " The horse has bolted. "; echo "|$new_string|"; echo "<br>"; echo "|".trim($new_string)."|";
| The horse has bolted. | |The horse has bolted.|
Note that the spaces in between words still exists with the use of trim().