目录

PHP ob_gzhandler() 函数

❮ PHP 输出控制函数

示例

向页面添加 gzip 压缩:

<?php
ob_start("ob_gzhandler");
echo "Hello World!";
?>
亲自试一试 »

定义和用法

该函数旨在作为回调传递给ob_start()。它使用浏览器支持的压缩算法压缩输出缓冲区的内容并返回压缩内容。它还发送一个 HTTP 标头,指示使用了哪种压缩算法。


语法

当用作回调时ob_start()

ob_start("ob_gzhandler");

单独使用时:

ob_gzhandler(buffer, phase);

参数值

Parameter Description
buffer The contents of the output buffer
phase A bitmask which may have any number of the following flags:
PHP_OUTPUT_HANDLER_START - If the output buffer was just created
PHP_OUTPUT_HANDLER_FLUSH - If the output buffer is currently being flushed
PHP_OUTPUT_HANDLER_FINAL - If the output buffer will be deleted right after this operation

技术细节

返回值: 返回包含压缩内容的字符串
PHP 版本: 4.0.4+

❮ PHP 输出控制函数