gzcompress()
gzcompress() — Compress a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function compresses the given string using the ZLIB data format.
Signature
gzcompress(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_DEFLATE): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $data | string | The data to compress. |
| $level | int | The level of compression. Can be given as 0 for no compression up to 9 for maximum compression. |
| $encoding | int | One of ZLIB_ENCODING_* constants. |
Return value
The compressed string or false if an error occurred.
Example
A runnable snippet:
$compressed = gzcompress('Compress me', 9); echo $compressed;
See also
gzdeflate(), gzinflate(), gzuncompress(), gzencode()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page gzcompress() (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.