PHP fgetcsv () फ़ंक्शन
❮ पीएचपी फाइल सिस्टम संदर्भउदाहरण
खुली सीएसवी फ़ाइल से एक पंक्ति पढ़ें और आउटपुट करें:
<?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, अन्य त्रुटियों पर और EOF पर FALSE |
---|---|
पीएचपी संस्करण: | 4.0+ |
बाइनरी सुरक्षित: | हाँ, PHP में 4.3.5 |
पीएचपी चेंजलॉग: | PHP 5.3 - एस्केप पैरामीटर जोड़ा गया |
और ज्यादा उदाहरण
उदाहरण
CSV फ़ाइल की संपूर्ण सामग्री को पढ़ें और आउटपुट करें:
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ पीएचपी फाइल सिस्टम संदर्भ