PHP Class Minify_HTML, minify

This is a heavy regex-based removal of whitespace, unnecessary comments and tokens. IE conditional comments are preserved. There are also options to have STYLE and SCRIPT blocks compressed by callback functions. A test suite is available.
Datei anzeigen Open project: mrclay/minify Class Usage Examples

Protected Properties

Property Type Description
$_cssMinifier
$_isXhtml
$_jsCleanComments boolean
$_jsMinifier
$_placeholders
$_replacementHash

Public Methods

Method Description
__construct ( string $html, array $options = [] ) Create a minifier object
minify ( string $html, array $options = [] ) : string "Minify" an HTML page
process ( ) : string Minify the markeup given in the constructor

Protected Methods

Method Description
_commentCB ( $m )
_needsCdata ( $str )
_removeCdata ( $str )
_removePreCB ( $m )
_removeScriptCB ( $m )
_removeStyleCB ( $m )
_removeTextareaCB ( $m )
_reservePlace ( $content )

Method Details

__construct() public method

Create a minifier object
public __construct ( string $html, array $options = [] )
$html string
$options array 'cssMinifier' : (optional) callback function to process content of STYLE elements. 'jsMinifier' : (optional) callback function to process content of SCRIPT elements. Note: the type attribute is ignored. 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If unset, minify will sniff for an XHTML doctype.

_commentCB() protected method

protected _commentCB ( $m )

_needsCdata() protected method

protected _needsCdata ( $str )

_removeCdata() protected method

protected _removeCdata ( $str )

_removePreCB() protected method

protected _removePreCB ( $m )

_removeScriptCB() protected method

protected _removeScriptCB ( $m )

_removeStyleCB() protected method

protected _removeStyleCB ( $m )

_removeTextareaCB() protected method

protected _removeTextareaCB ( $m )

_reservePlace() protected method

protected _reservePlace ( $content )

minify() public static method

"Minify" an HTML page
public static minify ( string $html, array $options = [] ) : string
$html string
$options array 'cssMinifier' : (optional) callback function to process content of STYLE elements. 'jsMinifier' : (optional) callback function to process content of SCRIPT elements. Note: the type attribute is ignored. 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If unset, minify will sniff for an XHTML doctype.
return string

process() public method

Minify the markeup given in the constructor
public process ( ) : string
return string

Property Details

$_cssMinifier protected_oe property

protected $_cssMinifier

$_isXhtml protected_oe property

protected $_isXhtml

$_jsCleanComments protected_oe property

protected bool $_jsCleanComments
return boolean

$_jsMinifier protected_oe property

protected $_jsMinifier

$_placeholders protected_oe property

protected $_placeholders

$_replacementHash protected_oe property

protected $_replacementHash