[wd_asp elements=’search’ ratio=’100%’ id=1]

Show last 10 lines of text file

7th October 2014

Php - Miscellaneous

php codehaven

$lines=array();
$fp = fopen("userlog.txt", "r");
while(!feof($fp))
{
$line = fgets($fp, 4096);
array_push($lines, $line);
if (count($lines)>10)
array_shift($lines);
}
fclose($fp);

while ($a <= 10) { $a++; echo "
".$lines[$a];
}