zlib_encode

(PHP 5 >= 5.4.0, PHP 7)

zlib_encodeCompress data with the specified encoding

Description

zlib_encode ( string $data , int $encoding [, int $level = -1 ] ) : string

Compress data with the specified encoding.

Warning

This function is currently not documented; only its argument list is available.

Parameters

data

The data to compress.

encoding

The compression algorithm. Either ZLIB_ENCODING_RAW, ZLIB_ENCODING_DEFLATE or ZLIB_ENCODING_GZIP.

level

Return Values

Examples

Example #1 zlib_encode() example

<?php
$str 
'hello world';
$enc zlib_encode($strZLIB_ENCODING_DEFLATE);
echo 
bin2hex($enc);
?>

The above example will output:

789ccb48cdc9c95728cf2fca4901001a0b045d

See Also

add a note add a note

User Contributed Notes 2 notes

up
8
soywiz at gmail dot com
8 years ago
RFC 1950 - zlib
RFC 1951 - raw deflate
RFC 1952 - gzip

The $encoding parameter referers to the window bits. So you can encode in several formats:

<?php

// RFC 1950 - zlib
$compressedData = zlib_encode($uncompressedData, 15);

// RFC 1951 - raw deflate
$compressedData = zlib_encode($uncompressedData, -15);

// RFC 1952 - gzip
$compressedData = zlib_encode($uncompressedData, 31);

?>
up
3
mike at technomonk.com
6 years ago
Undocumented constants are:

ZLIB_ENCODING_RAW
ZLIB_ENCODING_GZIP
ZLIB_ENCODING_DEFLATE

Example code:

<?php

$in
='hello world';
$enc=zlib_encode($in, ZLIB_ENCODING_DEFLATE);
echo
zlib_decode($enc);
//outputs 'hello world'
?>
To Top