question about reading files in php

cyberps

Newbie
Joined
Jul 15, 2015
Messages
4
Reaction score
0
Hey folks,

I tried to use fgets() to read a file line by line using this code..
Code:
while(!feof($txt)){
echo fgets($txt) . "<br>";
}
fclose($txt);

its read the file from the first line till the last one

but I wanna read the file from the last line till the first one
how can I do that please ?
 
Try reading in the contents of the file, line by line, into an array then reversing the order.

Code:
<?php
$lines = file('filename.txt', FILE_IGNORE_NEW_LINES);
$reversed = array_reverse($lines);
?>
 
an options to:
PHP:
$filestring = file_get_contents($filename);
$filearray = explode("\n", $filestring);
 
Back
Top