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 Kimmo Laine on 02/08/07 12:47

"Ilkka Maatta" <ilkka.maatta@phnet.fi> wrote in message
news:WJEyh.7723$uy2.6490@reader1.news.saunalahti.fi...
> PHP code .....
>
> <?
> //Open file.
> $file=fopen("file.txt","r");
> //read file so long when it isn't end.
> while (!feof($file))
> {
> //read and print row + LF.
> $rivi=fgets($file,1024);
> print "$row<BR>";
> }
> //Close file.
> fclose($file);
> ?>
>
> ....is read file(ascii) and print it display.
>
> How i can read and print only last row - don't all row?


WTF? you asked the same stupid question already in sfnet.atk.ohjelmointi
some time ago and you got 3 replies explaing how. How many times must this
be explained to you?

1) a single line, the unoptimized easy way:
echo array_pop(file(("file.txt"));

2) modifying your code:
$file=fopen("file.txt","r");
while (!feof($file)){
$rivi=fgets($file,1024);
}
print "$row<BR>";
fclose($file);

3) the real hard-core *nix way:
passthru("tail -n 1 file.txt");
// This one really reads just the last line,
// not all the lines before it. KEWL!

4) using file_get_contents and explode just for fun:
$temp = explode("\r\n",file_get_contents("file.txt"));
echo $temp[sizeof($temp)];


--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация