gzencode

(PHP 4 >= 4.0.4)

gzencode -- Create a gzip compressed string

Description

string gzencode (string data [, int level])

This function returns a compressed version of the input data compatible with the output of the gzip program, or FALSE if an error is encountered. The optional parameter level can be given as 0 for no compression up to 9 for maximum compression, if not given the default compression level will be 1.

The resulting data contains the appropriate headers and data structure to make a standard .gz file, e.g.:

Example 1. Creating a gzip file


<?php
$data = implode("", "bigfile.txt");
$gzdata = gzencode($data, 9);
$fp = fopen("bigfile.txt.gz", "w");
fwrite($fp, $gzdata);
fclose($fp);
?>
      

For more information on the GZIP file format, see the document: GZIP file format specification version 4.3 (RFC 1952).

See also gzcompress(). gzuncompress(), gzdeflate(), gzinflate().