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

PHP realizes the function of compressing html

WBOY
Release: 2016-07-25 08:45:28
Original
1122 people have browsed it
  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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template