Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gzcompress

Description

The gzcompress of zlib for PHP compresses a string.

Syntax

gzcompress(
    string $data,
    int $level = -1,
    int $encoding = ZLIB_ENCODING_DEFLATE
): string|false

Parameters

data

The data to compress.

level

The level of compression.

Can be given as 0 for no compression up to 9 for maximum compression. If -1 is used, the default compression of the zlib library is used which is 6.

encoding

The encoding mode.

ConstantDescription
ZLIB_ENCODING_RAWDEFLATE algorithm as per RFC 1951.
ZLIB_ENCODING_DEFLATEZLIB compression algorithm as per RFC 1950.
ZLIB_ENCODING_GZIPGZIP algorithm as per RFC 1952.

Return

Returns the compressed string or false if an error occurred.

Examples

1 · data

<?

$data = "data";

$return = gzcompress($data);

echo $return;

?>
x�KI,I�

2 · level · 0

<?

$data = "data";
$level = 0;

$return = gzcompress($data, $level);

echo $return;

?>
x��data�

3 · level · 9

<?

$data = "data";
$level = 9;

$return = gzcompress($data, $level);

echo $return;

?>
x�KI,I�

4 · encoding · ZLIB_ENCODING_RAW

<?

$data = "data";
$level = -1;
$encoding = ZLIB_ENCODING_RAW;

$return = gzcompress($data, $level, $encoding);

echo $return;

?>
KI,I

5 · encoding · ZLIB_ENCODING_DEFLATE

<?

$data = "data";
$level = -1;
$encoding = ZLIB_ENCODING_DEFLATE;

$return = gzcompress($data, $level, $encoding);

echo $return;

?>
x�KI,I�

6 · encoding · ZLIB_ENCODING_GZIP

<?

$data = "data";
$level = -1;
$encoding = ZLIB_ENCODING_GZIP;

$return = gzcompress($data, $level, $encoding);

echo $return;

?>
�KI,Ic��
HomeMenu