在PHP中,可以使用gzcompress()
和gzuncompress()
函数来实现二进制数据的压缩和解压缩。
压缩数据:
$data = "Hello, World!";
$compressedData = gzcompress($data);
解压缩数据:
$uncompressedData = gzuncompress($compressedData);
echo $uncompressedData; // Output: Hello, World!
另外,也可以使用base64_encode()
和base64_decode()
函数来对二进制数据进行编码和解码,从而实现数据的压缩和解压缩:
$data = "Hello, World!";
$compressedData = base64_encode(gzcompress($data));
$uncompressedData = gzuncompress(base64_decode($compressedData));
echo $uncompressedData; // Output: Hello, World!