Hello,
You can feof function to check the end of file. Please see the modified code below.
$file = fopen("m.txt","r+") or exit("couldn't open file");
while(!feof($file) {
echo fgets($file) . "<br />";
}
fclose($file);
For fgets function if you do not specify the length then it will keep reading from the stream until it reaches the end of the line.
To read a file line by line see code below.
You could try the following way
<?php
$file1 = "G:\\Events.txt";
$lines = file($file1);
foreach($lines as $line_num =?> $line) {
echo $line;
}
?>
OR
<?php $strFile = "G:\\Events.txt";
$hFile = fopen($strFile, "r");
while (($line = fgets($hFile)) !== false) {
echo $line;
}
?>
Regards,
Regards,