Skip to content

Instantly share code, notes, and snippets.

@mepawan mepawan/compress.php
Created May 18, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.