What function can I use?
Use trim
to remove whitespace at the start and end of a string.
left most
ltrim('text');
right most
rtrim('text');
but shortcut of above two is simply
trim('text');
string trim ( string $str [, string $charlist ] )
This function returns a string with whitespace stripped from the beginning and end of str
http://php.net/manual/en/function.trim.php would be your best choice
Checkout PHP Trim.