note 56554 deleted from function.file by mazzanet
| From: | mazzanet@php.net | Date: | Wed, 07 Sep 2005 08:35:25 +0000 |
| Subject: | note 56554 deleted from function.file by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94846@lists.php.net to get a copy of this message | ||
Note Submitter: asubstitute at gmail dot com
----
Here is a function that is similar to 'tail' on *nix systems.
<?php
function viewLog($log, $lines, $start, $end) {
global $vars;
global $style;
$file = file($log);
$file = array_reverse($file);
for ($line = 0; $line < $lines; $line++) {
if (isset($file[$line])) {
echo $file[$line] . $end;
}
}
unset($file)
}
?>
You use it like viewLog("/apache/logs/access.log", 10, "",
"<br>"); this would display the ten most recent lines from /apache/logs/access.log
and ending each line with a <br>.
If you wanted each line in a table row, you could do this:
viewLog("/apache/logs/access.log", 10, "<tr><td>",
"</td></tr>");
Manual:
viewLog(string logfile, int lines to display, string start_line, string end_line);
Hope this helps someone!