How to read file Line by Line in PHP ?

To read a file in PHP Line by Line

fgets() – This function take two parameter one as file and second length. This  returns a line from an open file.

Synatax
fgets( file, length )

PHP Code

<?php
$file=fopen(“num.txt”,”r”);
while(!feof($file))
print fgets($file).”<br/>”;
fclose($file);
?>

File (num.txt)

10
12
15
7
98
14
17
76

Output

Leave a Reply