You Now Here »

Tutorial PHP compress HTML auto remove whitespace break line clear output code  (Read 2412 times - 95 votes) 

DANNY

G-Plus Author
  • ADMINISTRATOR
  • More Share Forum Topic
  • [MS] kepala suku
  • *
  • DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!
  • Rep Power: 6
  • Join: September 30, 2009
  • Posts: 11,931
  • Poin: 193.394
    • WWW
  • IP member tracker Logged


oke sobat moreshare forum, pembelajaran kali ini adalah kita akan melakukan compressing pada file coding HTML dan output akan menghasilkan tampilan rapat sourcode untuk meningkatkan pagespeed google insights. proses ini akan dilakukan dalam PHP. silakan simak contoh berikut:

Original HTML sourcecode
Code: (index.php) [Select]
<html>
<head>
</head>
<body>
<div>
</div>
</body>
</html>

Compressing Code
Code: (index.php) [Select]
<?php 
//add this START before HTML code 
ob_start('compress_html'); 
?>

<html>
<head>
</head>
<body>
<div>
</div>
</body>
</html>
<?php
//add this END after HTML code
ob_end_flush();
function 
compress_html($compress)
    {
$i = array('/\s+/','/>\s</');
$ii = array(' ','><');
return 
preg_replace($i$ii$compress);
    }
?>


OUTPUT clear after compressing
Code: (index.php) [Select]
<html><head></head><body><div></div></body></html>

moga bermanfaat
  :matabelo


View Mobile Web Short URL: