Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * HTML output minifier
- * @author Jefrey <jefrey[at]jefrey[dot]ml>
- * /
- /*
- Include this code **at the end** of all your scripts that produces output you want to be minified (or use auto_prepend_file in .htaccess or php.ini, if supported by your host).
- This is supposed to be a simple solution, a trick/workaround (whatever you want to call this). If you want something more professional consider choosing a framework or dependency.
- Known issues:
- - Text between <textarea> and <code> will also lose tabs/new lines.
- */
- $buffer = ob_get_clean();
- // remove duplicated spaces
- while(strpos($buffer, " ")) {
- $buffer = str_replace(" ", " ", $buffer);
- }
- // remove tabulation
- $buffer = str_replace("\t", null, $buffer);
- // remove newlines
- $buffer = str_replace("\n", null, $buffer);
- $buffer = str_replace("\r", null, $buffer);
- echo $buffer;
Add Comment
Please, Sign In to add comment