gzgets()
gzgets() — Get line from file pointer.
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
Gets a (uncompressed) string of up to length - 1 bytes read from the given file pointer. Reading ends when length - 1 bytes have been read, on a newline, or on EOF (whichever comes first).
Signature
gzgets(resource $stream, ?int $length = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $stream | resource | The gz-file pointer. It must be valid, and must point to a file successfully opened by gzopen(). |
| $length | ?int | The length of data to get. |
Return value
The uncompressed string, or false on error.
Example
A runnable snippet:
$handle = gzopen('somefile.gz', 'r'); while (!gzeof($handle)) { $buffer = gzgets($handle, 4096); echo $buffer; } gzclose($handle);
Changelog
| Version | Change |
|---|---|
| 8.0.0 | length is nullable now; previously, the default was 1024. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page gzgets() (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.