gzencode php demo,PHP gzencode 用法 手册 | 示例代码

I was almost discouraged when I didn't find a gzdecode() function!  However, fear not, for I'll contribute my work... :)

function alt_gzdecode($str) {

// seed with microseconds since last "whole" second.

mt_srand((float)microtime()*1000000);

$eh="/tmp/php-" . md5(mt_rand(0,mt_getrandmax())) . ".gz";

$fd=fopen($eh,"w");

fwrite($fd,$str);

fclose($fd);

$fd = gzopen ($eh, "r");

$str=gzpassthru($fd);

unlink($eh);

return $str;

}

It's only ugly point is that it does not check to see if the file already exists.  You may also have to adjust reference names like $str and $fd if they stomp on your code. (Sorry, but this is all you get atm! ;} )  If your conserned about a race condition, cry for a internal gzdecode() function that actualy functions...

I spent about 3 hours straight debugging this problem.  I know the input data was valid, becuase I validated it with MD5() to compare to the md5's I had made of the input data before hand.  I'm not sure whats up with gzuncompress or gzinflate, but this works in its place . . .

Enjoy!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值