PHP compressed HTML page code (clear spaces, line breaks, tabs, comment tags, etc.) method

Source: Internet
Author: User
Tags php form
    1. /**
    2. * Compress HTML: Clear line break, clear tab, remove comment mark
    3. * @param $string
    4. * The $string after @return compression
    5. * from:bbs.it-home.org
    6. * */
    7. function compress_html ($string) {
    8. $string = Str_replace ("\ r \ n", ", $string); Clear line break
    9. $string = Str_replace ("\ n", "", $string); Clear line break
    10. $string = Str_replace ("\ T", "', $string); Clear tabs
    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. ?>
Copy Code

>>> You may be interested in the article:php stripped string newline instance parsing php compressed HTML (clear line breaks, clear tabs, remove comment marks) PHP form to convert textarea line breaks PHP regular filter HTML tags , spaces, line breaks, and so on. Php method for removing newline characters provides several ways to replace line breaks in PHP PHP generates Excel and controls line breaks in Excel 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.