You are here: Re: How read ONLY last row ASCII file « PHP Programming Language « IT news, forums, messages
Re: How read ONLY last row ASCII file

Posted by Kurt Milligan on 02/08/07 12:44

On Feb 8, 7:31 am, "Ilkka Maatta" <ilkka.maa...@phnet.fi> wrote:
>
> How i can read and print only last row - don't all row?

If you are in a *nix system, you can do:

$lastLine = exec('tail -1 getCodeGetText.php');

Another option, much more memory intensive (for large files), but
works on any system:

$lines = file('/path/to/filename.txt');
$lastLine = $lines[(count($lines) - 1)];

Or, you could loop the lines like you are doing already and just not
print out the lines;
the last line will be the last iteration through the loop.

while (!feof($file))
$line = fgets($fp,1024);

print $line;

HTH
-Kurt

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация