12.4. Compression

These functions compress and decompress strings using the bzip2 or gzip libraries. There are functions described in Chapter 9 for reading and writing to compressed files.

string bzcompress(string data, integer blocksize, integer workfactor)

Use bzcompress (Listing 12.60) to compress a string using the bzip2 library. The optional blocksize argument may be set with an integer from 1 to 9, with 9 being the highest compression. By default, blocksize is 4. The optional workfactor argument influences how bzcompress handles long strings of repetitive sequences. It should be an integer from 0 to 250.

Listing 12.60. bzcompress, bzdecompress
 <?php $text = "Core PHP Programming"; $bzText = bzcompress($text, 9); print(bin2hex($bzText) ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.