How can stream_get_line() be effectively used to read output from a stream in PHP, especially when dealing with custom line endings?

When dealing with custom line endings in PHP, the stream_get_line() function can be effectively used to read output from a stream. By specifying the custom line ending in the function parameters, we can ensure that the function reads the stream correctly. This allows for more flexibility when working with streams that have non-standard line endings.

$handle = fopen('example.txt', 'r');
$customLineEnding = "\r\n"; // specify custom line ending here
$line = stream_get_line($handle, 4096, $customLineEnding);
fclose($handle);

echo $line;