zlib_encode()
zlib_encode() — Compress data with the specified encoding.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.4.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
zlib_encode(string $data, int $encoding, int $level = -1): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $data | string | The data to compress. |
| $encoding | int | The compression algorithm. Either ZLIB_ENCODING_RAW, ZLIB_ENCODING_DEFLATE or ZLIB_ENCODING_GZIP. |
| $level | int |
Return value
See the PHP manual for the return value.
Example
A runnable snippet:
$str = 'hello world'; $enc = zlib_encode($str, ZLIB_ENCODING_DEFLATE); echo bin2hex($enc);
Output:
789ccb48cdc9c95728cf2fca4901001a0b045d
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page zlib_encode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.