警告:gzdecode():php中的数据错误 [英] Warning: gzdecode(): data error in php

查看:125
本文介绍了警告:gzdecode():php中的数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经问过了,但是我无法解决我的问题,所以我在这里解释了我的问题,请帮我解决这个问题.

I know this question already asked, but I can't solve my problem, so I explained my problem here kindly help me to solve this.

我正在通过使用file_get_contens()从此示例URL获取数据

I am getting data form this example URL by using file_get_contens()

$URL1 = 'abcd.com/xxx';
$URL2 = 'abcd.com/yyy';
$URL3 = 'abcd.com/zzz';

$response1 = file_get_contents($URL1);
$response2 = file_get_contents($URL2);
$response3 = file_get_contents($URL3);

然后我使用gzencode压缩了响应数据,因为数据太长并添加了前缀供我参考 然后我将压缩数据保存到数据库

And I compressed response data using gzencode because data too long and added prefix for my reference then i save compressed data to DB

$arrayResponse['URL1'] = '_|_coMpResSed_|_' . gzencode($response1);
$arrayResponse['URL2'] = '_|_coMpResSed_|_' . gzencode($response2);
$arrayResponse['URL3'] = '_|_coMpResSed_|_' . gzencode($response3);

数据库详细信息

  • 存储引擎:InnoDB
  • 整理:utf8mb4_unicode_ci
  • 类型:longblob或longtext(我都尝试过)

然后我使用gzdecode解压缩数据

And I decompress the data by using gzdecode

$temp1 = explode('_|_coMpResSed_|_', $arrayResponse['URL1']);
$temp2 = explode('_|_coMpResSed_|_', $arrayResponse['URL2']);
$temp3 = explode('_|_coMpResSed_|_', $arrayResponse['URL3']);

if (!empty($temp1[1]) && !empty($temp2[1]) && !empty($temp3[1])) {
    $arrayResponse['URL1'] = gzdecode($temp1[1]);//working fine 
    $arrayResponse['URL2'] = gzdecode($temp2[1]);// getting warning 
    $arrayResponse['URL3'] = gzdecode($temp3[1]);//working fine     
}

我得到警告:

gzdecode():数据错误on line $ arrayResponse ['URL2'] = gzdecode($ temp2 [1]);`

gzdecode(): data erroron line$arrayResponse['URL2'] = gzdecode($temp2[1]);`

其他行工作正常.我不知道我在哪里犯错误.有人可以帮我得到这个吗?

Other lines are working fine . I dont know where I am making mistakes. Can any one help me to get this?

推荐答案

遇到同样的问题,我只是看了一下Mysql doc: https://dev.mysql.com/doc/refman/5.5 /en/encryption-functions.html

Having same problem, I just had a look at Mysql doc: https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html

许多加密和压缩函数都返回字符串,其结果可能包含任意字节值.如果要存储这些结果,请使用具有 VARBINARY BLOB 二进制字符串数据类型的列.这样可以避免因删除尾随空格或字符集转换而引起的潜在问题,这些问题可能会更改数据值,例如,如果您使用非二进制字符串数据类型(CHAR,VARCHAR,TEXT),则可能会发生这种情况.

Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type. This will avoid potential problems with trailing space removal or character set conversion that would change data values, such as may occur if you use a nonbinary string data type (CHAR, VARCHAR, TEXT).

我只是将列数据类型更改为VARBINARY,所以一切正常.

I just change the column data type to VARBINARY and everything's OK.

这篇关于警告:gzdecode():php中的数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆