-
- /**
- * Compress html: clear newlines, clear tabs, remove comment marks
- * @param $string
- * @return compressed $string
- * from: bbs.it-home.org
- **/
- 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 (
- "/> *([^ ]*) *", //Remove the comment mark
- "/[s]+/",
- "// ",
- "/" /",
- "/ "/",
- "'/*[^*]**/'"
- );
- $replace = array (
- ">\1<",
- " ",
- "",
- """,
- """,
- ""
- );
- return preg_replace($pattern, $replace, $string);
- }
- ?>
Copy code
>>>> Articles you may be interested in:
php remove string newline character instance analysis
php compress html (clear newlines, clear tabs, remove comment marks)
How to convert textarea line breaks in php forms
Code examples of php regular filtering html tags, spaces, newlines, etc.
Summary of how to remove line breaks in php
Provide several php methods to replace newline characters
php generates excel and controls line breaks in Excel cells
|