Home > Backend Development > PHP Tutorial > PHP compresses html web page code (remove spaces, newlines, tabs, comment marks)_PHP tutorial

PHP compresses html web page code (remove spaces, newlines, tabs, comment marks)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:20:09
Original
876 people have browsed it

PHP compresses html web page code (remove spaces, newlines, tabs, comment marks).
A good method is to compress HTML. Compressing HTML actually means: clearing newlines, clearing tabs, and removing comment marks. The role it plays cannot be underestimated.
Now provides PHP compressed HTML function. Please give it a try, it feels good.

No more nonsense, just go to the code:

Copy the code The code is as follows:

/**
* Compress HTML: clear newlines, clear tabs, remove comment marks
* @param $string
* @return compressed $string
**/
function compress_html($string) {
$string = str_replace("rn", '', $string); //Clear newlines
$string = str_replace("n", '', $string); //Clear newline characters
$string = str_replace("t", '', $string); //Clear tab characters
$pattern = array (
"/> *([^ ]*) *"/[s]+/",
"//",
"/" /",
"/ "/",
"'/*[^*]**/'"
);
$replace = array (
">\1<",
" ",
"",
""",
""",
""
);
return preg_replace($pattern, $replace, $string);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325172.htmlTechArticlePHP compresses html web page code (clear spaces, newlines, tabs, comment marks). A good method is to compress HTML. Compressing HTML actually means: clearing newlines, clearing tabs, removing...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template