02/18/2019   Comments Off on Compress HTML output with PHP

View all snippets

Wrap your PHP or HTML with this code and it will remove spaces, line breaks thus minifying your code.

<?php function ob_html_compress($buf){
return str_replace(array("\n","\r","\t"),'',$buf);
}; ob_start("ob_html_compress"); // compress head HTML ?>

Your PHP or HTML here...

<?php ob_end_flush(); // end compress head HTML ?>