Function name: stream_get_line()
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Function description: The stream_get_line() function reads a line of content from the file pointer and returns the line of content.
Usage: stream_get_line(resource $handle, int $length, string $ending = ?): string|false
parameter:
Return value:
Example:
$handle = fopen("example.txt", "r"); if ($handle) { $line = stream_get_line($handle, 1024, "\n"); echo $line; fclose($handle); }
In the example above, we open a file named "example.txt" and then use the stream_get_line() function to read a line from the file pointer and store it in the variable $line. Finally, we output the line content to the screen.
Note that if the file pointer reaches the end of the file or the number of bytes read reaches the specified maximum number of bytes, the stream_get_line() function stops reading and returns false. Therefore, in actual applications, we need to judge whether a row of content has been successfully read based on the return value.