Skip to content

Commit 7420e70

Browse files
committed
V 1.0
1 parent fdff89b commit 7420e70

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

html-minifier.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* StagON Name: HTML Minifier
4+
* StagON Text Domain: html-minifier
5+
* StagON URI: https://stagphp.io
6+
* StagON Description: This StagON minifies the HTML output
7+
* Version: 1.0
8+
* Author: StagPHP
9+
* License: GPL3
10+
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
11+
*/
12+
13+
14+
function sanitize_output($buffer) {
15+
$search = array(
16+
'/\>[^\S ]+/s', // strip white spaces after tags, except space
17+
'/[^\S ]+\</s', // strip white spaces before tags, except space
18+
'/(\s)+/s', // shorten multiple whitespace sequences
19+
'/<!--(.|\s)*?-->/' // Remove HTML comments
20+
);
21+
22+
$replace = array(
23+
'>',
24+
'<',
25+
'\\1',
26+
''
27+
);
28+
29+
$buffer = preg_replace($search, $replace, $buffer);
30+
31+
return $buffer;
32+
}
33+
34+
function minified_output(){
35+
echo sanitize_output(ob_get_clean());
36+
}
37+
38+
stag_add_action('processed', 'minified_output', TRUE);

0 commit comments

Comments
 (0)