Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<stream_get_filtersstream_get_meta_data>
^Stream FunctionsLast updated: Mon, 26 Oct 2026

stream_get_line

(PHP 5, PHP 7, PHP 8)

stream_get_line — Gets line from stream resource up to a given delimiter

Description

function stream_get_line(resource $stream, int $length, string $ending = ""): string|false

Gets a line from the given handle.

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).

This function is nearly identical to fgets() except in that it allows end of line delimiters other than the standard \n, \r, and \r\n, and does not return the delimiter itself.

Parameters

stream

A valid file handle.

length

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

An optional string delimiter.

Return Values

Returns a string of up to length bytes read from the file pointed to by stream, or false on failure.

Errors/Exceptions

Throws a ValueError if length is negative.

Changelog

Version Description
8.0.0 Now throws a ValueError if length is negative. Previously, an E_WARNING was raised and false was returned.

See Also

  • fread() - Binary-safe file read
  • fgets() - Gets line from file pointer
  • fgetc() - Gets character from file pointer

<stream_get_filtersstream_get_meta_data>
^Stream FunctionsLast updated: Mon, 26 Oct 2026