Php Laravel中的压缩HTML仍然包含空格

Php Laravel中的压缩HTML仍然包含空格,php,laravel-4,Php,Laravel 4,我使用下面的代码压缩Laravel中的HTML输出;我把它放在filters/App::after函数中 if (App::Environment() != 'local') { if ($response instanceof Illuminate\Http\Response) { $output = $response->getOriginalContent(); // Clean comments $output = preg

我使用下面的代码压缩Laravel中的HTML输出;我把它放在filters/App::after函数中

if (App::Environment() != 'local') {
    if ($response instanceof Illuminate\Http\Response) {
        $output = $response->getOriginalContent();

        // Clean comments
        $output = preg_replace('/<!--([^\[|(<!)].*)/', '', $output);
        $output = preg_replace('/(?<!\S)\/\/\s*[^\r\n]*/', '', $output);
        // Clean Whitespace
        $output = preg_replace('/\s{2,}/', '', $output);
        $output = preg_replace('/(\r?\n)/', '', $output);
        $response->setContent($output);
    }
}

它修复了符号错误,但HTML输出无法正常工作。一些空白未被删除。有人能帮我吗?

您是否启用了mbstring php扩展?请显示输入、输出和预期输出。当然,这只是一个很小的例子。而且,压缩每个请求的响应似乎效率低下。如果您使用的是刀片视图,那么在使用blade::extend查看更多信息编译视图时压缩内容是有意义的。mbstring php扩展已启用。您好,您需要查看包含所有压缩类型的my library。
$output = preg_replace('/\s{2,}/', '', $output);