Um do you want compression or removal of whitespace? As Brij pointed out the trim() function will remove both leading and training whitespace.
If you want real compression and your PHP is compiled --with-zlib you should try gzcompress() and gzuncompress().
Dominique