PHP fgets() Functie
❮ Referentie voor PHP-bestandssysteemVoorbeeld
Lees een regel uit het geopende bestand:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
Definitie en gebruik
De functie fgets() retourneert een regel uit een geopend bestand.
Syntaxis
fgets(file, length)
Parameterwaarden
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 |
Technische details
Winstwaarde: | Een enkele regel gelezen uit het bestand bij succes, FALSE bij EOF of fout |
---|---|
PHP-versie: | 4.0+ |
Binaire kluis: | Ja, in PHP 4.3 |
Meer voorbeelden
Voorbeeld
Open bestand lezen, regel voor regel:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮ Referentie voor PHP-bestandssysteem