I used this regex for me and it works like a charm:
preg_replace('/[ \t]+(?!="|\')/', '', $html);
These pattern looks for space whitespace and tabulator (at least one), that is not followed by " or '. This is, to avoid removing whitespaces between html attributes.