PHP ob_gzhandler() Function
The PHP ob_gzhandler() function is intended to be used as a callback function for ob_start(). It compresses the contents of the output buffer using a compression algorithm that is supported by the browser and returns the compressed content. It also sends an HTTP header indicating which compression algorithm was used. If a browser doesn't support compressed pages this function returns false.
Note: ob_gzhandler() function requires the zlib extension.
Syntax
ob_gzhandler(buffer, mode)
Parameters
buffer |
Optional. Specify the content of the output buffer. |
mode |
Optional. A bitmask which may have any number of the following modes:
|
Return Value
Returns a string containing the compressed contents.
Example: ob_gzhandler() example
The example below shows the usage of ob_gzhandler() function.
<?php ob_start("ob_gzhandler"); ?> <html> <body> <p>This should be a compressed page.</p> </body> </html>
The output of the above code will be a compressed page.
❮ PHP Output Control Reference