"Ilkka Maatta" <il**********@phnet.fiwrote in message
news:WJ*****************@reader1.news.saunalahti.f i...
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
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)