php gzcompress编码问题 [英] php gzcompress encoding issue
问题描述
问题:
您好,我使用了php的gzcompress函数来压缩php curl请求的Google页面.我将其存储为html文件,但在gzuncompress上,某些字符无法正确解码.该页面来自google lietuvos.
Hi, I used gzcompress function of php to compress a google page requested from php curl. I stored it as a html file but on gzuncompress some characters are not decoded correctly.The page was from google lietuvos.
代码:
// Encoding used in curl request
curl_setopt($ch, CURLOPT_ENCODING , 'gzip,deflate');
//Compressing
gzcompress($res['page'],9);
// Uncompressing
gzuncompress($data);
请让我知道我是否有任何遗漏?谢谢.在此处输入图片说明
Please let me know if I am missing anything? Thank you.enter image description here
推荐答案
鉴于我们掌握的信息很少,我认为这是换行符和字符为"\ 0"
( null
字符).
Given the little information we have, I assume that this is a problem with newlines and with the encoding having the character "\0"
(null
character) somewhere.
您可以执行以下操作:
压缩页面并编码为base64:
Compress the page and encode to base64:
base64_encode(gzcompress($res['page'],9));
要解压缩,请从base64解码:
To decompress, decode from base64:
gzuncompress(base64_decode($data));
这将确保一切都按原样进行写入和读取,而开销大约为33%.
This will ensure that everything will be written and read as-is, with around 33% of overhead.
对于此问题,还有其他解决方案,但这是最简单的.
There are other solutions for this problem, but this is the easiest.
这篇关于php gzcompress编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!