stream_get_line()
stream_get_line() — Gets line from stream resource up to a given delimiter.
Built-in function of PHP 8.5. The manual lists it as available in 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
Reading ends when length bytes have been read, when the non-empty string specified by ending is found (which is not included in the return value), or on EOF (whichever comes first).
Signature
stream_get_line(resource $stream, int $length, string $ending = ""): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $stream | resource | A valid file handle. |
| $length | int | The maximum number of bytes to read from the handle. Negative values are not supported. Zero (0) means the default socket chunk size, i.e. 8192 bytes. |
| $ending | string | An optional string delimiter. |
Return value
Returns a string of up to length bytes read from the file pointed to by stream, or false on failure.
Example
The PHP manual ships no example for stream_get_line(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | Now throws a ValueError if length is negative. Previously, an E_WARNING was raised and false was returned. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_get_line() (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.