title: How can I automatically minify my webpages?
body: <p>All of my .html and .php webpages should be minified. That means I would like to get all HTML-comments and more than one whitespace-character stripped.</p>
  
  <p>Does an Apache-module exist for minification? 
  (Or perhaps another method to automatically add a script directly before the output gets sent to the user?)</p>
  
  <p>(I could add a function like the following, but if an Apache-module or another automatic solution existed, I could not forget to do so.)</p>
  
  <pre><code>&lt;?
  function sanitize_output($buffer)
  {
      $search = array(
          '/\&gt;[^\S ]+/s', //strip whitespaces after tags, except space
          '/[^\S ]+\&lt;/s', //strip whitespaces before tags, except space
          '/(\s)+/s'  // shorten multiple whitespace sequences
          );
      $replace = array(
          '&gt;',
          '&lt;',
          '\\1'
          );
    $buffer = preg_replace($search, $replace, $buffer);
      return $buffer;
  }   
  ?&gt;
  </code></pre>