|
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]
|