Jump to Navigation

042 - How to get last lines in a million lines file.

Example:

$i=0 ;
$lines=20 ;
$file = 'file_name.txt';
$fp = fopen($file,"r") ;
if(is_resource($fp)){
fseek($fp,0,SEEK_END) ;
$a = ftell($fp) ;
while($i <= $lines){
if(fgetc($fp) == "\n"){
echo (fgets($fp)) . "<br />";
$i++ ;
}
fseek($fp,$a) ;
$a-- ;
}
}
PHP:


Main menu 2

Story | by Dr. Radut