Possible Duplicate:
How to minify php page html output?
I mean strip out all the line breaks and spaces in html and puts it on one line.
I tried this function
public static function htmlCompress($html)
{
    preg_match_all('!(<(?:code|pre|script).*>[^<]+</(?:code|pre|script)>)!',$html,$pre);
    $html = preg_replace('!<(?:code|pre).*>[^<]+</(?:code|pre)>!', '#pre#', $html);
    $html = preg_replace('#<!–[^\[].+–>#', '', $html);
    $html = preg_replace('/[\r\n\t]+/', ' ', $html);
    $html = preg_replace('/>[\s]+</', '><', $html);
    $html = preg_replace('/[\s]+/', ' ', $html);
    if (!empty($pre[0])) {
        foreach ($pre[0] as $tag) {
            $html = preg_replace('!#pre#!', $tag, $html,1);
        }
    }
    return $html;
}
but sometimes appears symbols like "�" because of this string
$html = preg_replace('/[\s]+/', ' ', $html);
Why appears this symbol and how to compress html?
 
     
     
     
    