Home >Backend Development >PHP Tutorial >PHP realizes the function of compressing html

PHP realizes the function of compressing html

WBOY
WBOYOriginal
2016-07-25 08:45:281111browse
  1. function compress_html($string) {
  2. $string = str_replace("rn", '', $string); //Clear newlines
  3. $string = str_replace("n", '', $string); //Clear newline characters
  4. $string = str_replace("t", '', $string); //Clear tab characters
  5. $pattern = array (
  6. "/> *([^ ]*) * "/[s]+/",
  7. "//",
  8. "/" /",
  9. "/ "/",
  10. "'/*[^*]**/'"
  11. );
  12. $replace = array (
  13. ">\1<",
  14. " ",
  15. "",
  16. """ ,
  17. """,
  18. ""
  19. );
  20. return preg_replace($pattern, $replace, $string);
  21. }
Copy code

PHP, html


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