Home  >  Article  >  Backend Development  >  PHP compressed html function code

PHP compressed html function code

WBOY
WBOYOriginal
2016-07-25 08:55:32985browse
  1. //Function name: compress_html
  2. //Parameters: $string
  3. //Return value: Compressed $string
  4. //by bbs.it-home.org
  5. function compress_html($ string) {
  6. $string = str_replace("rn", '', $string); //Clear newline characters
  7. $string = str_replace("n", '', $string); //Clear newline characters
  8. $string = str_replace("t", '', $string); //Clear tab characters
  9. $pattern = array (
  10. "/> *([^ ]*) * "/[s]+/",
  11. "//",
  12. "/" /",
  13. "/ "/",
  14. " '/*[^*]**/'"
  15. );
  16. $replace = array (
  17. ">\1<",
  18. " ",
  19. "",
  20. """,
  21. """,
  22. " "
  23. );
  24. return preg_replace($pattern, $replace, $string);
  25. }
Copy code


Statement:
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