LMLPHP后院

PHP解压函数gzdecode和gzinflate使用方法技术

maybe yes 发表于 2015-01-21 00:11

PHP 5.4 之后新增的 gzip 解压函数 gzdecode 使用方法,gzdecode — Decodes a gzip compressed string,解压一个使用 gzip 压缩的字符串,这是官网手册上面写到的。

目前很多的空间服务商的 PHP 版本都没有达到 5.4 ,这也导致使用此函数之后发生函数未定义错误,该如何解决这个问题呢?PHP 官方网站用户提交的日志中有人给出了很好的解决方案,使用 gzinflate 函数代替,代码参考如下:

<?php
if (!function_exists('gzdecode')) {
	function gzdecode($data)
	{
		return gzinflate(substr($data,10,-8));
	}
}

gzinflate 函数的功能大致和 gzdecode 相似,在返回值的注解中官方给出了一句提示“The function will return an error if the uncompressed data is more than 32768 times the length of the compressed input data or more than the optional parameter length. ”。

相关文章
2024-04-23 22:05:03 1713881103 0.007731