php remove whitespace in string apart from single spaces code example Example: remove empty spaces php $string = str_replace(' ', '', $string);