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.
<?php
$filename = "log.txt";
$logfile = fopen($filename, "r");
$line = fgets($logfile);
print "First line of $filename is: $line";
?> The first line of log.txt is: Sample code running This code reads and prints a line of text from a file.