在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!