当前位置:Gxlcms > PHP教程 > PHP实现压缩html的函数

PHP实现压缩html的函数

时间:2021-07-01 10:21:17 帮助过:18人阅读

  1. function compress_html($string) {
  2. $string = str_replace("\r\n", '', $string); //清除换行符
  3. $string = str_replace("\n", '', $string); //清除换行符
  4. $string = str_replace("\t", '', $string); //清除制表符
  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. }

PHP, html

人气教程排行