PHP fgetcsv() Fungsi
Referensi Sistem File PHPContoh
Baca dan keluarkan satu baris dari file CSV yang terbuka:
<?php
$file = fopen("contacts.csv","r");
print_r(fgetcsv($file));
fclose($file);
?>
Definisi dan Penggunaan
Fungsi fgetcsv() mem-parsing baris dari file yang terbuka, memeriksa bidang CSV .
Tip: Lihat juga fungsi fputcsv() .
Sintaksis
fgetcsv(file, length, separator, enclosure)
Nilai Parameter
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 "\\" |
Detail Teknis
Nilai Kembali: | Larik dengan bidang CSV jika berhasil, NULL jika file yang diberikan tidak valid, FALSE pada kesalahan lain dan pada EOF |
---|---|
Versi PHP: | 4.0+ |
Biner Aman: | Ya, di PHP 4.3.5 |
Log Perubahan PHP: | PHP 5.3 - Menambahkan parameter escape |
Lebih Banyak Contoh
Contoh
Baca dan hasilkan seluruh konten file CSV:
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
Referensi Sistem File PHP