Forum Moderators: coopster
<?php
$myfile = "test.txt";
$file = fopen($myfile, "r") or exit("Unable to open file!");
$lines_read = 0;
$first_line = '';
while(!feof($file) && $lines_read < 1) {
$lines_read++;
$first_line = fgets($file);
}
fclose($file);
if($lines_read == 1) {
echo "The first line of $myfile reads: $first_line";
} else {
echo "Could not read from file";
}
?>
I've found this flag doesn't work too well under windows
$len = count($fields); // So Readie doesn't yell at me. :-)
$file = ('/path/to/file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);