Re: PHP a funkce

From: Spock (spock@bfs.cz)
Date: 11. 01. 2000, 12:09 CET


>prosim Vas neporadil by jste mi nekdo zda-li existuje funkce ktera by
>precetla urcitou radku ze souboru. Nemam tim namysli funkci FGetS
>protoze pouze prvni.
>S pozdravem Pavel Trefny

chces-li n-ty radek, proste udelas fgets n krat. fgets totiz presune
pointer na misto, kde skoncilo cteni, tedy na dalsi radek.

$n=10;
$fd = fopen("/nekde/neco.txt", "r");
for ($i=0; $i<$n; $i++) $radek=fgets($fd, 8192);
# v $radek je ted $n-ty radek ze souboru neco.txt
fclose($fd);

nebo, jak pise jakub, nacist soubor do array - je to obecne rychlejsi,
ale na druhe strane  _vzdycky_  nacita cely (treba dlouhy) soubor:

$pole=file("/nekde/neco.txt");
$radek=$pole[$n-1];
# v $radek je ted $n-ty radek ze souboru neco.txt

z obou moznosti si muzes udelat funkci ktera vrati pozadovany radek:
string radek(string file, int ktery)
a radeji taky jeste ten kod osetrit na vyskyt moznych chyb.

Bye, Spock.



This archive was generated by hypermail 2.1.2 : 03. 09. 2001, 22:34 CEST