PHP: gzgets - Manual (original) (raw)
(PHP 4, PHP 5, PHP 7, PHP 8)
gzgets — Get line from file pointer
Description
Parameters
stream
The gz-file pointer. It must be valid, and must point to a file successfully opened by gzopen().
length
The length of data to get.
Return Values
The uncompressed string, or [false](reserved.constants.php#constant.false) on error.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | length is nullable now; previously, the default was 1024. |
Examples
Example #1 gzgets() example
<?php
$handle = gzopen('somefile.gz', 'r');
while (!gzeof($handle)) {
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mi>u</mi><mi>f</mi><mi>f</mi><mi>e</mi><mi>r</mi><mo>=</mo><mi>g</mi><mi>z</mi><mi>g</mi><mi>e</mi><mi>t</mi><mi>s</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">buffer = gzgets(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">b</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mord mathnormal" style="margin-right:0.02778em;">er</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.04398em;">z</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">s</span><span class="mopen">(</span></span></span></span>handle, 4096);
echo $buffer;
}
gzclose($handle);
?>See Also
- gzopen() - Open gz-file
- gzgetc() - Get character from gz-file pointer
- gzwrite() - Binary-safe gz-file write
Found A Problem?
6 years ago
PS when it encounters and breaks on a newline byte ("\n"), the newline byte itself is not included in the returned string.