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.
Afficher le fichier Open project: mrclay/minify Class Usage Examples

Protected Properties

Свойство Type Description
$_cssMinifier
$_isXhtml
$_jsCleanComments boolean
$_jsMinifier
$_placeholders
$_replacementHash

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode Description
_commentCB ( $m )
_needsCdata ( $str )
_removeCdata ( $str )
_removePreCB ( $m )
_removeScriptCB ( $m )
_removeStyleCB ( $m )
_removeTextareaCB ( $m )
_reservePlace ( $content )

Method Details

__construct() public méthode

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 méthode

protected _commentCB ( $m )

_needsCdata() protected méthode

protected _needsCdata ( $str )

_removeCdata() protected méthode

protected _removeCdata ( $str )

_removePreCB() protected méthode

protected _removePreCB ( $m )

_removeScriptCB() protected méthode

protected _removeScriptCB ( $m )

_removeStyleCB() protected méthode

protected _removeStyleCB ( $m )

_removeTextareaCB() protected méthode

protected _removeTextareaCB ( $m )

_reservePlace() protected méthode

protected _reservePlace ( $content )

minify() public static méthode

"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.
Résultat string

process() public méthode

Minify the markeup given in the constructor
public process ( ) : string
Résultat string

Property Details

$_cssMinifier protected_oe property

protected $_cssMinifier

$_isXhtml protected_oe property

protected $_isXhtml

$_jsCleanComments protected_oe property

protected bool $_jsCleanComments
Résultat boolean

$_jsMinifier protected_oe property

protected $_jsMinifier

$_placeholders protected_oe property

protected $_placeholders

$_replacementHash protected_oe property

protected $_replacementHash