Conditions | 1 |
Paths | 1 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
46 | public static function compress($html) |
||
47 | { |
||
48 | $filters = array( |
||
49 | // remove javascript comments |
||
50 | '/(?:<script[^>]*>|\G(?!\A))(?:[^\'"\/<]+|"(?:[^\\"]+|\\.)*"|\'(?:[^\\\']+|\\.)*\'|\/(?!\/)|<(?!\/script))*+\K\/\/[^\n|<]*/xsu' => '', |
||
51 | // remove html comments except IE conditions |
||
52 | '/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/su' => '', |
||
53 | // remove comments in the form /* */ |
||
54 | '/\/+?\s*\*[\s\S]*?\*\s*\/+/u' => '', |
||
55 | // shorten multiple white spaces |
||
56 | '/>\s{2,}</u' => '><', |
||
57 | // shorten multiple white spaces |
||
58 | '/\s{2,}/u' => ' ', |
||
59 | // collapse new lines |
||
60 | '/(\r?\n)/u' => '', |
||
61 | ); |
||
62 | |||
63 | $output = preg_replace(array_keys($filters), array_values($filters), $html); |
||
64 | |||
65 | return $output; |
||
66 | } |
||
67 | } |
||
68 |