O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required