Re: Read Last Lines of a Text File

From: Date: Thu, 17 Jun 2004 16:01:48 +0000
Subject: Re: Read Last Lines of a Text File
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-188498@lists.php.net to get a copy of this message
Scott Miller wrote:
----- Original Message ----- From: "Oliver Hankeln" <oha@walter-interactive.de> To: <php-general@lists.php.net> Sent: Thursday, June 17, 2004 9:29 AM Subject: Re: [PHP] Read Last Lines of a Text File
Scott Miller wrote:
I've changed my script to the following: <?php $file ="/var/log/radius.log"; $fp = popen("/usr/bin/tail -$limit $file", 'r'); if (! $fp ) { echo 'unable to pipe command'; } while (!feof($fp) ) { $line = fgets($fp); print $line; } ?> And now get the following errors: Warning: Wrong parameter count for fgets() in /var/www/html/logs2.php
on
line 10 I get this over and over and over (like it's producing the error once
per
line in the log file).
prior to PHP 4.2 you had to use a second parameter for fgets. This parameter is the maximum length per line to read. $line = fget($fp,4096); will probably work. HTH, Oliver
Changed that line as shown above, and now get the following error: Fatal error: Call to undefined function: fget() in
/var/www/html/logs2.php
on line 11
Sorry. I mean fgets ...
That worked perfectly - now I at least get this: [snip]
Now, how can I force a \n; to make it look like this:
Simply add one. print $line."\n"; should work. Or if your output is html print $line."<br>"; Oliver

« previous php.general (#188498) next »