note 56554 added to function.file
| From: | asubstituteatgmaildotcom at osu1 dot php dot net | Date: | Wed, 07 Sep 2005 08:31:02 +0000 |
| Subject: | note 56554 added to function.file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94845@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/function.file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56554
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56554&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56554&report=yes
Search -- http://master.php.net/manage/user-notes.php