>  기사  >  백엔드 개발  >  PHP压缩html的函数代码

PHP压缩html的函数代码

WBOY
WBOY원래의
2016-07-25 08:55:32937검색
  1. //函数名: compress_html
  2. //参数: $string
  3. //返回值: 压缩后的$string
  4. //by bbs.it-home.org
  5. function compress_html($string) {
  6. $string = str_replace("\r\n", '', $string); //清除换行符
  7. $string = str_replace("\n", '', $string); //清除换行符
  8. $string = str_replace("\t", '', $string); //清除制表符
  9. $pattern = array (
  10. "/> *([^ ]*) *", //去掉注释标记
  11. "/[\s]+/",
  12. "//",
  13. "/\" /",
  14. "/ \"/",
  15. "'/\*[^*]*\*/'"
  16. );
  17. $replace = array (
  18. ">\\1 " ",
  19. "",
  20. "\"",
  21. "\"",
  22. ""
  23. );
  24. return preg_replace($pattern, $replace, $string);
  25. }
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.