';
function __minifyx($input) {
return str_replace(array("\n", "\t", ' '), array(X . '\n', X . '\t', X . '\s'), $input);
}
function __minifyv($input) {
return str_replace(array(X . '\n', X . '\t', X . '\s'), array("\n", "\t", ' '), $input);
}
/**
* =======================================================
* HTML MINIFIER
* =======================================================
*/
function __replace_html_style_for_minify($m) {
return $m[1] . $m[2] . minify_css($m[3]) . $m[2];
}
function __replace_html_for_minify($m) {
if(isset($m[2])) {
// Minify inline CSS declaration(s)
if(stripos($m[2], ' style=') !== false) {
$m[2] = preg_replace_callback('#( style=)([\'"]?)(.*?)\2#i', '__replace_html_style_for_minify', $m[2]);
}
return '<' . $m[1] . preg_replace(
array(
// From `defer="defer"`, `defer='defer'`, `defer="true"`, `defer='true'`, `defer=""` and `defer=''` to `defer` [^1]
'#\s(checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)(?:=([\'"]?)(?:true|\1)?\2)#i',
// Remove extra white-space(s) between HTML attribute(s) [^2]
'#\s*([^\s=]+?)(=(?:\S+|([\'"]?).*?\3)|$)#',
// From `` to `
` [^3]
'#\s+\/$#'
),
array(
// [^1]
' $1',
// [^2]
' $1$2',
// [^3]
'/'
),
str_replace("\n", ' ', $m[2])) . '>';
}
return '<' . $m[1] . '>';
}
function _minify_html($input) {
return preg_replace_callback('#<\s*([^\/\s]+)\s*(?:>|(\s[^<>]+?)\s*>)#', '__replace_html_for_minify', $input);
}
function minify_html($input) {
if( ! $input = trim($input)) return $input;
global $CH;
// Keep important white-space(s) after self-closing HTML tag(s)
$input = preg_replace('#(<(?:img|input)(?:\s[^<>]*?)?\s*\/?>)\s+#i', '$1' . X . '\s', $input);
// Create chunk(s) of HTML tag(s), ignored HTML group(s), HTML comment(s) and text
$input = preg_split('#(' . $CH . '|
|\s[^<>]*?>)[\s\S]*?<\/pre>||\s[^<>]*?>)[\s\S]*?<\/code>|