title: minify html output from php file, with a script
body: <p>I want to minify the output html from php file, I have followed this guide:</p>
  
  <p><a href="https://stackoverflow.com/questions/6225351/how-to-minify-php-page-html-output">How to minify php page html output?</a></p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  
  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;
  }
  
  ob_start("sanitize_output");
  
  ?&gt;
  </code></pre>
  
  <p>The page minify, but my slider on the homepage disappears. I have nivo slider which you can see here:</p>
  
  <p><a href="https://github.com/gilbitron/nivo-slider" rel="nofollow noreferrer">https://github.com/gilbitron/nivo-slider</a></p>
  
  <p>This is the code I have in my page for the nivo slider:</p>
  
  <pre><code>&lt;div id="featured"&gt;
      &lt;div id="slides"&gt;
          &lt;div id="slider" class="nivoSlider"&gt;
              &lt;?
              $is_first_image = TRUE;
              foreach($_info["img_slider_homepage"]["src"] as $indice=&gt;$src)
              {
                  $href       = $_info["img_slider_homepage"]["href"][$indice];
                  $alt        = $_info["img_slider_homepage"]["alt"][$indice];
                  $capt_id    = $_info["img_slider_homepage"]["capt_id"][$indice];
                  $capt_txt   = $_info["img_slider_homepage"]["capt_txt"][$indice];
                  $title      = ($capt_id
                                  ? "#".$capt_id
                                  : $_info["img_slider_homepage"]["title"][$indice]);
  
                  if($href)
                  {
                      ?&gt;&lt;a href="&lt;?=$href?&gt;" class="&lt;?=$is_first_image ? "" : "lazywait"?&gt;"&gt;&lt;img src="&lt;?=$src?&gt;" title="&lt;?=$title?&gt;" alt="&lt;?=$alt?&gt;" width="&lt;?=$_info["img_slider_width"]?&gt;" height="&lt;?=$_info["img_slider_height"]?&gt;"&gt;&lt;/a&gt;&lt;?
                  }
                  else
                  {
                      ?&gt;&lt;img src="&lt;?=$src?&gt;" class="&lt;?=$is_first_image ? "" : "lazywait"?&gt;" title="&lt;?=$title?&gt;" alt="&lt;?=$alt?&gt;" width="&lt;?=$_info["img_slider_width"]?&gt;" height="&lt;?=$_info["img_slider_height"]?&gt;"&gt;&lt;?
                  }
  
                  $is_first_image = FALSE;
              }
              ?&gt;
          &lt;/div&gt;
  
          &lt;?
          foreach($_info["img_slider_homepage"]["src"] as $indice=&gt;$src)
          {
              $capt_id    = $_info["img_slider_homepage"]["capt_id"][$indice];
              $capt_txt   = $_info["img_slider_homepage"]["capt_txt"][$indice];
  
              if($capt_id AND $capt_txt)
              {
                  ?&gt;
                  &lt;div id="&lt;?=$capt_id?&gt;" class="nivo-html-caption"&gt;
                      &lt;?=$capt_txt?&gt;
                  &lt;/div&gt;
                  &lt;?
              }
          }
          ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>this is autput html:</p>
  
  <pre><code>&lt;body &gt;
  
  &lt;div id="container"&gt;&lt;div id="row"&gt;&lt;div id="header_home_page"&gt; &lt;ul id="top-menu"&gt;&lt;ul id="nullo" class="sf-menu"&gt; &lt;li&gt;&lt;a class="tito" href="/amministra/"&gt;&lt;img src="/inc/files/images/adminplus.png"&gt;&lt;/a&gt;&lt;div class="ams"&gt;AMMINISTRA&lt;/div&gt; &lt;ul&gt; &lt;/ul&gt; &lt;/li&gt;&lt;/ul&gt; &lt;li&gt;&lt;a href="/vacanze_weekend/"&gt;Vacanze&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/matrimoni/"&gt;Matrimoni&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/meeting/"&gt;Meeting&lt;/a&gt;&lt;/li&gt; &lt;/li&gt;&lt;li&gt;&lt;span class="current-lang"&gt;ita&lt;/span&gt; | &lt;a href="/en/" title="English - Luxury hotels and historical boutique hotels"&gt;ENG&lt;/a&gt;&lt;/li&gt;&lt;div id="additional-info"&gt;&lt;div id="search-form"&gt;&lt;form action="/chi_siamo/cerca.php" id="cse-search-box"&gt; &lt;input type="hidden" name="cx" value="010014129502104197540:hsefbn00beg" /&gt; &lt;input type="hidden" name="cof" value="FORID:11" /&gt; &lt;input type="hidden" name="ie" value="UTF-8" /&gt; &lt;input type="text" name="q" size="25" id="searchinput"/&gt;&lt;input type="image" src="/inc/files/images/search_btn.png" id="searchsubmit" /&gt;&lt;/form&gt;&lt;/div&gt; &lt;!-- end #search-form --&gt;&lt;/div&gt;&lt;/ul&gt;&lt;div class="wrap"&gt;&lt;div id="branding"&gt;&lt;div class="logohome"&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt; &lt;/div&gt;&lt;/div&gt;&lt;div id="additional-info"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="featured"&gt;&lt;div id="slides"&gt;&lt;div id="slider" class="nivoSlider"&gt;&lt;img src="/inc/files/images/slider/mntr2.jpg" class="" title="" alt="" width="960" height="332"&gt;&lt;img src="/inc/files/images/slider/cimb1.jpg" class="lazywait" title="" alt="" width="960" height="332"&gt;&lt;img src="/inc/files/images/slider/murl2.jpg" class="lazywait" title="" alt="" width="960" height="332"&gt;&lt;img src="/inc/files/images/slider/pvch1.jpg" class="lazywait" title="" alt="" width="960" height="332"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script src="/inc/script/jquery.nivo.slider.pack.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script src="/inc/script/lazyload.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;$(window).load(function() { $('#slider').nivoSlider({ effect: 'random', // Specify sets like: 'fold,fade,sliceDown' animSpeed: 500, // Slide transition speed pauseTime: 3000, // How long each slide will show startSlide: 0, // Set starting Slide (0 index) directionNav: true, // Next &amp; Prev navigation directionNavHide: true, // Only show on hover controlNav: true, // 1,2,3... navigation controlNavThumbs: true, // Use thumbnails for Control Nav controlNavThumbsFromRel: true, // Use image rel for thumbs controlNavThumbsSearch: '.jpg', // Replace this with... keyboardNav: true, // Use left &amp; right arrows pauseOnHover: true, // Stop animation while hovering manualAdvance: false, // Force manual transitions captionOpacity: 0.8, // Universal caption opacity prevText: 'Prev', // Prev directionNav text nextText: 'Next', // Next directionNav text randomStart: false, // Start on a random slide beforeChange: function(){}, // Triggers before a slide transition afterChange: function(){}, // Triggers after a slide transition slideshowEnd: function(){}, // Triggers after all slides have been shown lastSlide: function(){}, // Triggers when last slide is shown afterLoad: function(){} // Triggers when slider has loaded });
  });&lt;/script&gt;&lt;div id="category-name" style="padding-top:38px;"&gt; &lt;div id="category-inner"&gt; &lt;h3&gt;Siamo specializzati in Vacanze ed Eventi di Alto Livello&lt;br&gt;in dimore storiche di pregio con almeno 100 anni di storia&lt;/h3&gt;&lt;p&gt;Le nostre dimore storiche hanno in media solo 11 camere e ospitano un solo evento in esclusiva al giorno&lt;/p&gt; &lt;/div&gt;&lt;/div&gt; &lt;!-- end .category-name --&gt; ecc
  </code></pre>