Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to Compress HTML Code using PHP

php html
How to Compress HTML Code using PHP

Compressing the code is very beneficial for a website it increases website performance and load it faster by making webpage smaller and lighter and it also affects website SEO, so this script strips out all the line breaks and spaces in your code and puts it on one line, compressing your code and making it faster. You may also like How to Disable AutoComplete Form using jQuery.

PHP and HTML Code


function compress_code($code) {
    $search = array(
        '/\>[^\S ]+/s',
        '/[^\S ]+\</s',

    $replace = array('>', '<', '\\1');
    $code = preg_replace($search, $replace, $code);
    return $code;
        <p>How to Compress HTML Code using PHP</p>



Html code work in comment box

Related Post