-
/**
- * 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 (
- "/> *([^ ]*) *
"/[s]+/",
- "/
/ ",
- "/" /",
- "/ "/",
- "'/*[^*]**/'"
- );
- $replace = array (
- ">\1<",
- " ",
- "",
- """,
- """,
- ""
- );
- return preg_replace($pattern, $replace, $string);
- }
- ?>
Copy code
>>>> Articles you may be interested in:php remove string newline character instance analysisphp compress html (clear newlines, clear tabs, remove comment marks)How to convert textarea line breaks in php formsCode examples of php regular filtering html tags, spaces, newlines, etc.Summary of how to remove line breaks in phpProvide several php methods to replace newline charactersphp generates excel and controls line breaks in Excel cells |