. * * @version 1.0 * @author Simon Wippich * @copyright Copyright (c) 2009, Simon Wippich * @license http://www.gnu.org/licenses/ GNU Lesser General Public License */ namespace Qs\Packer; use Exception; class Html { /** * Method for compressing HTML-sourcecode. * * @access public * @param $htmlSourceCode String The original HTML-sourcecode * @param $removeComments bool * @return String The compressed HTML-sourcecode * @throws Exception */ final public static function compressHtml($htmlSourceCode, $removeComments = true) { try { // Check if the given parameter matches datatype string if (is_string($htmlSourceCode)) { // Exclude pre- or code-tags preg_match_all( '!(<(?:code|pre|textarea).*>[^<]+)!', $htmlSourceCode, $pre ); // Remove all pre- or code-tags $htmlSourceCode = preg_replace( '!<(?:code|pre|textarea).*>[^<]+!', '#pre#', $htmlSourceCode ); // Exclude all value attributes preg_match_all( '!((?:value=\")[^\"]*(?:\"))!', $htmlSourceCode, $value ); // Remove all value attributes $htmlSourceCode = preg_replace( '!((?:value=\")[^\"]*(?:\"))!', '#value#', $htmlSourceCode ); // Remove HTML-comments if required if ($removeComments === true) { $htmlSourceCode = preg_replace( '/\