Funkce PHP fgets().
❮ Reference souborového systému PHPPříklad
Přečtěte si jeden řádek z otevřeného souboru:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
Definice a použití
Funkce fgets() vrací řádek z otevřeného souboru.
Syntax
fgets(file, length)
Hodnoty parametrů
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a line from |
length | Optional. Specifies the number of bytes to read. Reading stops when length-1 bytes have been reached, or when a new line occurs, or on EOF. If no length is specified, it reads until end of the line |
Technické údaje
Návratová hodnota: | Jeden řádek přečtený ze souboru při úspěchu, FALSE při EOF nebo chybě |
---|---|
Verze PHP: | 4,0+ |
Binární trezor: | Ano, v PHP 4.3 |
Další příklady
Příklad
Číst otevřený soubor řádek po řádku:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮ Reference souborového systému PHP