Blogroll

Tuesday, July 17, 2012

Compress html with php

Compress html help you load page with faster speed, delete your html comment.
Fist : save out html and call function when page load done.
Put below code before show your html code.


 ob_start('html_compression_finish');
Next is function to remove all new line code.
function removeWhiteSpace($html, $full_html)
	{
		$html = str_replace("\t", ' ', $html);
		$html = str_replace("\r", ' ', $html);
		$html = str_replace("\n", ' ', $html);
		
		// This is over twice the speed of a RegExp
		while (strpos($html, '  ') !== false)
		{
			$html = str_replace('  ', ' ', $html);
		}
		
		return $html;
	}
Finnally put below code when your html loaded,(Put in footer,....)
 function minifyHTML($html)
	{
		$pattern = '/<(?
Olá! Se você ainda não assinou, assine nosso RSS feed e receba nossas atualizações por email, ou siga nos no Twitter.
Nome: Email:

0 comments:

Post a Comment