How can PHP be used to compress HTML pages?

To compress HTML pages using PHP, you can utilize the ob_gzhandler() function in PHP. This function enables output buffering and gzip compression, reducing the size of HTML pages before sending them to the client's browser. By compressing HTML pages, you can improve website loading times and save bandwidth.

<?php
ob_start("ob_gzhandler");
echo "<html><body><h1>Compressed HTML Page</h1></body></html>";
ob_end_flush();
?>