If you need to trim the white space for HTML code and don't rely on spaces for formatting text (if you are then it is time to use Style Sheets) then this code will come in very useful.
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
$data=eregi_replace(">"."[[:space:]]+",">",$data);
$data=eregi_replace("[[:space:]]+"."<","<",$data);