I fyou just want to trim the string (i.e. remove whitespace from the beginning and of the string), use the trim operator. If you want to remove whitespace from the middle of the string you might need a preg_replace functionality, which is offered by this extension: