Skip to content

Instantly share code, notes, and snippets.

@mepawan
Created May 18, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mepawan/5f280d260ba3f019e2f8fdacf5cfd7f1 to your computer and use it in GitHub Desktop.
Save mepawan/5f280d260ba3f019e2f8fdacf5cfd7f1 to your computer and use it in GitHub Desktop.
CodeIgniter Compre Output
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function compress()
{
$CI =& get_instance();
$buffer = $CI->output->get_output();
$search = array(
'/\>[^\S ]+/s',
'/[^\S ]+\</s',
'/(\s)+/s', // shorten multiple whitespace sequences
'#(?://)?<!\[CDATA\[(.*?)(?://)?\]\]>#s' //leave CDATA alone
);
$replace = array(
'>',
'<',
'\\1',
"//&lt;![CDATA[\n".'\1'."\n//]]>"
);
$buffer = preg_replace($search, $replace, $buffer);
$CI->output->set_output($buffer);
$CI->output->_display();
}
/* End of file compress.php */
/* Location: ./system/application/hooks/compress.php */
//------system/application/hooks/compress.php
?>
<?php
//------system/application/config/config.php
$config['enable_hooks'] = TRUE;
?>
<?php
//------system/application/config/hooks.php
// compress output
$hook['display_override'][] = array(
'class' => '',
'function' => 'compress',
'filename' => 'compress.php',
'filepath' => 'hooks'
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment