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 အကွက်များပါရှိသော array တစ်ခု၊ မမှန်ကန်သော ဖိုင်ကို ပေးဆောင်ပါက NULL ၊ အခြားအမှားများနှင့် EOF တွင် မှားနေသည် |
---|---|
PHP ဗားရှင်း- | 4.0+ |
Binary Safe- | PHP 4.3.5 တွင် ဟုတ်ကဲ့ |
PHP Changelog- | PHP 5.3 - escape parameter ကို ပေါင်းထည့်ထားသည်။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
CSV ဖိုင်တစ်ခု၏ အကြောင်းအရာတစ်ခုလုံးကို ဖတ်ပြီး ထုတ်ပေးပါ-
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ PHP ဖိုင်စနစ် အကိုးအကား