Posted By

iroybot on 09/12/09


Tagged

php white space line break


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

vali29
iroybot
nerdfiles
wirenaught
gecube


HTML compression // white space removal


 / Published in: PHP
 

i know these regex stuff is rather slow, but still i like having slim documents. (don't forget to use gzip compression on all text docs)

  1. /**
  2.  * @param $string (X)HTML document string
  3.  * @return string
  4.  * @todo benchmark/optimize performance
  5.  */
  6. private function minimizeHTML($string) {
  7. // will remove tabs, line breaks and extra white spaces
  8. $r = preg_replace(array('/\r/','/\n/','/
  9. /','/\t/'),'',$string);
  10. $r = preg_replace('/\s\s+/',' ',$out);
  11. return $r;
  12. }

Report this snippet  

You need to login to post a comment.