PHP fgetcsv() İşlevi
❮ PHP Dosya Sistemi ReferansıÖrnek
Açık CSV dosyasından bir satır okuyun ve çıktısını alın:
<?php
$file = fopen("contacts.csv","r");
print_r(fgetcsv($file));
fclose($file);
?>
Tanım ve Kullanım
fgetcsv() işlevi, açık bir dosyadan bir satırı ayrıştırarak CSV alanlarını kontrol eder .
İpucu: Ayrıca fputcsv() işlevine bakın.
Sözdizimi
fgetcsv(file, length, separator, enclosure)
Parametre Değerleri
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 "\\" |
Teknik detaylar
Geri dönüş değeri: | Başarı durumunda CSV alanlarını içeren bir dizi, geçersiz bir dosya sağlanırsa NULL, diğer hatalar ve EOF'de FALSE |
---|---|
PHP Sürümü: | 4.0+ |
İkili Kasa: | Evet, PHP 4.3.5'te |
PHP Değişiklik Günlüğü: | PHP 5.3 - Kaçış parametresi eklendi |
Daha fazla örnek
Örnek
Bir CSV dosyasının tüm içeriğini okuyun ve çıktısını alın:
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ PHP Dosya Sistemi Referansı