ltrim and rtrim removes whitespaces on the left and right of a string. check those.
also, to remove characters from a string
$string = " hello&hi!";
//Remove Whitespace
$string = ltrim("$string");
//Remove & and !
$string = str_replace("&", "", $string);
$string = str_replace("!", "", $string);
For Regular Expressions replace:
preg_replace();