输入banner图图片脚本导航/分类

php压缩html网页代码(清除空格、换行符、制表符、注释标记等)的方法

  1. /**
  2. * 压缩html : 清除换行符,清除制表符,去掉注释标记
  3. * @param $string
  4. * @return 压缩后的$string
  5. * from: bbs.it-home.org
  6. * */
  7. function compress_html($string) {
  8. $string = str_replace("\r\n", '', $string); //清除换行符
  9. $string = str_replace("\n", '', $string); //清除换行符
  10. $string = str_replace("\t", '', $string); //清除制表符
  11. $pattern = array (
  12. "/> *([^ ]*) *"/[\s]+/",
  13. "//",
  14. "/\" /",
  15. "/ \"/",
  16. "'/\*[^*]*\*/'"
  17. );
  18. $replace = array (
  19. ">\\1<",
  20. " ",
  21. "",
  22. "\"",
  23. "\"",
  24. ""
  25. );
  26. return preg_replace($pattern, $replace, $string);
  27. }
  28. ?>

>>> 您可能感兴趣的文章: php去除字符串换行符实例解析 php压缩html(清除换行符,清除制表符,去掉注释标记) php表单中转换textarea换行符的方法 php正则过滤html标签、空格、换行符等的代码示例 php去除换行符的方法小结 提供几个php替换换行符的方法 php生成excel与控制Excel单元格中的换行符