how to remove line breaks and spaces from string php code example Example: string remove line breaks php preg_replace( "/\r|\n/", "", $yourString );