PHP » I/O » fgets()

Syntax:
string fgets(int file [, int length])
file
File handle of the file to read a line from.
length
Maximum length for the line.

Reads a line from a file.

fgets() is a convenient function when a text file is to be read line by line. It returns a line from the file, up to and including the next new line character. The optional length parameter can be used to set a maximum length on the returned result. If the call fails, FALSE is returned.

Examples

Code:
<?php

$filename = "log.txt";

$logfile = fopen($filename, "r");
$line = fgets($logfile);
print "First line of $filename is: $line";

?>
Output:
The first line of log.txt is: Sample code running
Explanation:

This code reads and prints a line of text from a file.

See Also: