Php compresses html webpage code (clear spaces, line breaks, tabs, comment tags, etc.)

Source: Internet
Author: User
Tags php excel php form php regular expression
Php compresses html webpage code (clear spaces, line breaks, tabs, comment tags, etc.)

  1. /**
  2. * Html compression: clear line breaks, clear tabs, and remove comment tags
  3. * @ Param $ string
  4. * @ Return $ string after compression
  5. * From: bbs.it-home.org
  6. **/
  7. Function compress_html ($ string ){
  8. $ String = str_replace ("\ r \ n", '', $ string); // clear line breaks
  9. $ String = str_replace ("\ n", '', $ string); // clear the line break
  10. $ String = str_replace ("\ t", '', $ string); // clear the tab
  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. ?>

>>> Articles you may be interested in: php removes the string line break instance parsing php compresses html (clear line breaks, clear tabs, remove comment tags) php form conversion textarea linefeed method php regular expression filtering html tags, spaces, linefeeds and other code examples php method to remove linefeeds summary several php methods to replace linefeeds php excel generation and control Excel line breaks in cells

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.