system/application/config/config.php
$config['enable_hooks'] = TRUE;
system/application/config/hooks.php
// compress output $hook['display_override'][] = array( 'class' => '', 'function' => 'compress', 'filename' => 'compress.php', 'filepath' => 'hooks' );
system/application/hooks/compress.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); function compress() { $CI =& get_instance(); $buffer = $CI->output->get_output(); $search = array( '/\n/', // replace end of line by a space '/\>[^\S ]+/s', // strip whitespaces after tags, except space '/[^\S ]+\</s', // strip whitespaces before tags, except space '/(\s)+/s' // shorten multiple whitespace sequences ); $replace = array( ' ', '>', '<', '\\1' ); $buffer = preg_replace($search, $replace, $buffer); $CI->output->set_output($buffer); $CI->output->_display(); } /* End of file compress.php */ /* Location: ./system/application/hools/compress.php */
$options = array( 'clean' => true, 'hide-comments' => true, 'indent' => true ); $buffer = tidy_parse_string($buffer, $options, 'utf8'); tidy_clean_repair($buffer); // warning: if you generate XML, HTML Tidy will break it (by adding some HTML: doctype, head, body..) if not configured properly