首頁  >  文章  >  後端開發  >  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("rn", '', $string); //清除换行符
  7. $string = str_replace("n", '', $string); //清除换行符
  8. $string = str_replace("t", '', $string); //清除制表符
  9. $pattern = array (
  10. "/> *([^ ]*) * "/[s]+/",
  11. "//",
  12. "/" /",
  13. "/ "/",
  14. "'/*[^*]**/'"
  15. );
  16. $replace = array (
  17. "><",
  18. " ",
  19. "",
  20. """,
  21. """,
  22. ""
  23. );
  24. return preg_replace($pattern, $replace, $string);
  25. }
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn