دالة PHP fgetcsv ()
❮ مرجع نظام ملفات PHPمثال
قراءة وإخراج سطر واحد من ملف CSV المفتوح:
<?php
$file = fopen("contacts.csv","r");
print_r(fgetcsv($file));
fclose($file);
?>
التعريف والاستخدام
تقوم الوظيفة fgetcsv () بتوزيع سطر من ملف مفتوح ، والتحقق من حقول CSV .
نصيحة: راجع أيضًا وظيفة fputcsv () .
بناء الجملة
fgetcsv(file, length, separator, enclosure)
قيمه المعامل
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 "\\" |
تفاصيل تقنية
قيمة الإرجاع: | مصفوفة تحتوي على حقول CSV بنجاح ، و NULL إذا تم توفير ملف غير صالح ، و FALSE على أخطاء أخرى وعلى EOF |
---|---|
إصدار PHP: | 4.0+ |
ثنائي آمن: | نعم ، في PHP 4.3.5 |
سجل التغيير في PHP: | PHP 5.3 - تمت إضافة معامل الهروب |
مزيد من الأمثلة
مثال
قراءة وإخراج المحتويات الكاملة لملف CSV:
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ مرجع نظام ملفات PHP