Discussion board
How to read a File Line by Line?
By Balu Prasad
How to read a File Line by Line????
Reply
Post   Reset
Teacher SiliconIndia replied to Balu Prasad Wednesday, March 17, 2010
Hi Balu,
The fgets() function is used to read a single line from a file.
Note: After a call to this function the file pointer has moved to the next line.
Example
The example below reads a file line by line, until the end of file is reached:
<?php
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>