Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

php Read each line until end of file

Im trying to write a php script to read each line of a file, and continue looping until the end of the file is reached, but cannot find out how to detect the end of the file.

Code in vb.net would be:-
        FileOpen(1, "c:\temp.txt", OpenMode.Input)
        While EOF(1) = False
            inputStr = LineInput(1)
        End While

Only code I can really find at the moment, reads the top 3 lines of the file (I know I can repeat it xx times, but the file can be different lengths.

Any help would be appriciated.

Thanks in advance
$myFile = "C:\\phpTest\\testFile.txt";
$fh = fopen($myFile, 'r');
 
$theData = fgets($fh);
echo $theData;
 
$theData = fgets($fh);
echo $theData;
 
$theData = fgets($fh);
echo $theData;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Veonik
Veonik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial