PHP compresses HTML page code (clears spaces, line breaks, tabs, comment marks).
There is a good way to compress HTML, compressed HTML is actually: Clear line breaks, clear tabs, remove the annotation tag. The role it plays cannot be belittled.
now provides PHP compression HTML functions. Please try it, it feels good.
no nonsense, directly on the code:
Copy Code code as follows:
<?php
/**
* Compressed HTML: Clears line breaks, clears tabs, and removes comment marks
* @param $string
* @return Compressed $string
* */
function compress_html ($string) {
$string = Str_replace ("rn", "", $string); Clear line feed
$string = Str_replace ("n", "", $string); Clear line feed
$string = str_replace ("T", "", $string); Clear tab
$pattern = Array (
"/> * ([^]*) *</",//Remove comment Mark
"/[s]+/",
"/<!--[^!] *-->/",
"/" /",
"/ "/",
"'/*[^*]**/'"
);
$replace = Array (
">1<",
" ",
"",
""",
""",
""
);
return Preg_replace ($pattern, $replace, $string);
}
?>