gzread()

gzread() — Binary-safe gz-file read.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, 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

gzread() reads up to length bytes from the given gz-file pointer. Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first.

Signature

gzread(resource $stream, int $length): string|false

Parameters

ParameterTypeWhat it takes
$streamresourceThe gz-file pointer. It must be valid, and must point to a file successfully opened by gzopen().
$lengthintThe number of bytes to read.

Return value

The data that have been read, or false on failure.

Example

A runnable snippet:

// get contents of a gz-file into a string $filename = "/usr/local/something.txt.gz"; $zd = gzopen($filename, "r"); $contents = gzread($zd, 10000); gzclose($zd);

Changelog

VersionChange
7.4.0This functions returns false on failure now; previously 0 was returned.

See also

gzwrite(), gzopen(), gzgets(), gzfile(), gzpassthru()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page gzread() (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.