PHP output Compressed HTML page Code Instance program _php Tutorial

Source: Internet
Author: User
Tags wordpress blog
Compressing the page input is to remove all the unused characters, and then all the code together, so for the SEO is helpful, but for the code is very poor readability, we often see a lot of web sites to do so, if you want to manually spaces HTML in the word to delete the very troublesome, So there is the PHP output compressed HTML page instance.

Is it possible to compress the HTML code for the server output?

Here is a function to compress HTML:

The code is as follows Copy Code

function wpjam_minify_html ($html) {

$search = Array (
'/>[^s]+/s ',//Remove the space behind the label
'/[^s]+ '/(S) +/s '//combine multiple spaces into one
);

$replace = Array (
' > ',
' < ',
' \1 '
);

$html = Preg_replace ($search, $replace, $html);

return $html;
}

For WordPress Blog, the above function and the following code copied to the current theme of the functions.php file, you can implement the output page HTML code compression:

The code is as follows Copy Code


if (!is_admin ()) {
Add_action ("wp_loaded", ' wp_loaded_minify_html ');
function wp_loaded_minify_html () {
Ob_start (' wpjam_minify_html ');
}
}

Of course, the above is the site SEO optimization, we have a better way is to combine the above page compression output and then the server gzip compressed open, so that the page will be smaller oh, about Apacheapache server open gzip Compression instance

http://www.bkjia.com/PHPjc/632740.html www.bkjia.com true http://www.bkjia.com/PHPjc/632740.html techarticle compressing the page input is to remove all the unused characters, and then put all the code together, which is helpful for SEO, but for the code readability is very poor, we often see ...

  • Related Article

    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.