note 66727 added to function.fseek

From: Date: Sat, 27 May 2006 17:44:22 +0000
Subject: note 66727 added to function.fseek
Groups: php.notes 
Request: Send a blank email to php-notes+get-112374@lists.php.net to get a copy of this message
Here a little extension for the code of ekow. If you want to read more than one line and more than one file. Some times the last five ore ten lines are interesting in. You only have to submit a array with filenames and optionally a number of lines you want to read. <?php function read_logfiles($files, $lines=5) { foreach($files as $file_num => $file) { if (file_exists ($file) ) { $handle = fopen($file, "r"); $linecounter = $lines; $pos = -2; $t = " "; $text[$file_num] = ""; while ($linecounter > 0) { while ($t != "\n") { fseek($handle, $pos, SEEK_END); $t = fgetc($handle); $pos --; } $t = " "; $text[$file_num] .= fgets($handle); $linecounter --; } fclose ($handle); } else { $text[$file_num] = "The file doesn't exist."; } } return $text; ?> ---- Server IP: 217.13.201.10 Probable Submitter: 195.145.50.3 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.fseek.php Edit -- http://master.php.net/note/edit/66727 Del: integrated -- http://master.php.net/note/delete/66727/integrated Del: useless -- http://master.php.net/note/delete/66727/useless Del: bad code -- http://master.php.net/note/delete/66727/bad+code Del: spam -- http://master.php.net/note/delete/66727/spam Del: non-english -- http://master.php.net/note/delete/66727/non-english Del: in docs -- http://master.php.net/note/delete/66727/in+docs Del: other reasons-- http://master.php.net/note/delete/66727 Reject -- http://master.php.net/note/reject/66727 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112374) next »