PHP fgetcsv() Functie
❮ Referentie voor PHP-bestandssysteemVoorbeeld
Lees en voer één regel uit het geopende CSV-bestand uit:
<?php
$file = fopen("contacts.csv","r");
print_r(fgetcsv($file));
fclose($file);
?>
Definitie en gebruik
De functie fgetcsv() ontleedt een regel uit een open bestand en controleert op CSV-velden .
Tip: Zie ook de functie fputcsv() .
Syntaxis
fgetcsv(file, length, separator, enclosure)
Parameterwaarden
Parameter | Description |
---|---|
file | Required. Specifies the open file to return and parse a line from |
length | Optional. Specifies the maximum length of a line. Must be greater than the longest line (in characters) in the CSV file. Omitting this parameter (or setting it to 0) the line length is not limited, which is slightly slower. Note: This parameter is required in versions prior to PHP 5 |
separator | Optional. Specifies the field separator. Default is comma ( , ) |
enclosure | Optional. Specifies the field enclosure character. Default is " |
escape | Optional. Specifies the escape character. Default is "\\" |
Technische details
Winstwaarde: | Een array met de CSV-velden bij succes, NULL als een ongeldig bestand wordt aangeleverd, FALSE bij andere fouten en bij EOF |
---|---|
PHP-versie: | 4.0+ |
Binaire kluis: | Ja, in PHP 4.3.5 |
PHP-wijzigingslogboek: | PHP 5.3 - De escape - parameter toegevoegd |
Meer voorbeelden
Voorbeeld
Lees en voer de volledige inhoud van een CSV-bestand uit:
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ Referentie voor PHP-bestandssysteem