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

zlib_encode

Description

The zlib_encode of zlib for PHP compresses data with the specified encoding.

Syntax

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

Parameters

data

The data to compress.

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.

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.

Return

Returns the compressed string or false if an error occurred.

Examples

1 · data encoding · ZLIB_ENCODING_RAW

<?

$data = "data";
$encoding = ZLIB_ENCODING_RAW;

$return = zlib_encode($data, $encoding);

echo $return;

?>
KI,I

2 · data encoding · ZLIB_ENCODING_DEFLATE

<?

$data = "data";
$encoding = ZLIB_ENCODING_DEFLATE;

$return = zlib_encode($data, $encoding);

echo $return;

?>
x�KI,I�

3 · data encoding · ZLIB_ENCODING_GZIP

<?

$data = "data";
$encoding = ZLIB_ENCODING_GZIP;

$return = zlib_encode($data, $encoding);

echo $return;

?>
�KI,Ic��

4 · level · 0

<?

$data = "data";
$encoding = ZLIB_ENCODING_DEFLATE;
$level = 0;

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

echo $return;

?>
x��data�

5 · level · 9

<?

$data = "data";
$encoding = ZLIB_ENCODING_DEFLATE;
$level = 9;

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

echo $return;

?>
x�KI,I�
HomeMenu