How to compress html web page code in php (remove spaces, newlines, tabs, comment marks, etc.)

WBOY
Release: 2016-07-25 09:05:49
Original
923 people have browsed it
  1. /**
  2. * Compress html: clear newlines, clear tabs, remove comment marks
  3. * @param $string
  4. * @return compressed $string
  5. * from: bbs.it-home.org
  6. **/
  7. function compress_html($string) {
  8. $string = str_replace("rn", '', $string); //Clear newlines
  9. $ string = str_replace("n", '', $string); //Clear newline characters
  10. $string = str_replace("t", '', $string); //Clear tab characters
  11. $pattern = array (
  12. "/> *([^ ]*) * "/[s]+/",
  13. "/ / ",
  14. "/" /",
  15. "/ "/",
  16. "'/*[^*]**/'"
  17. );
  18. $replace = array (
  19. ">\1<",
  20. " ",
  21. "",
  22. """,
  23. """,
  24. ""
  25. );
  26. return preg_replace($pattern, $replace, $string);
  27. }
  28. ?>
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



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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!