This is the insert into file, it puts 1 row at a time. I want to read only last 10 rows, for example.
$file = SITE_ROOT."logs/log.txt";
if ($handle = fopen($file, 'a+b')) {
$content = Session::get('username') . " has logged out on - " . datetime_to_text("now") . "\r\n";
fwrite($handle, $content);
fclose($handle);
} else {
echo 'Culd not open file for writing.';
}
this is how i read them, reads them all.
$file = SITE_ROOT . "logs/log.txt";
$content = "";
if ($handle = fopen($file, 'r')) {
while (!feof($handle)) {
$content .= '<li><a href="#">' . fgets($handle) . '</a></li>';
echo count($handle);
}
fclose($handle);
}
echo nl2br($content);
How to read only 10?
Done, i found the answer i was looking for.
Thx, i found useffull this one.
$file = SITE_ROOT . "logs/log.txt";
$data = array_slice(file($file), -10);
$data1 = file($file);
foreach ($data as $line) {
echo '<li><a href="#">'. nl2br($line) . '</a></li>';
}