Join Up!
104886 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousfgetcfgetsnext
Last updated: Tue, 28 May 2002
view the printer friendly version or the printer friendly version with notes or change language to Czech | German | Spanish

fgetcsv

(PHP 3>= 3.0.8, PHP 4 >= 4.0.0)

fgetcsv -- Gets line from file pointer and parse for CSV fields

Description

array fgetcsv ( int fp, int length [, string delimiter [, string enclosure]])

Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV format and returns an array containing the fields read. The field delimiter is a comma, unless you specify another delimiter with the optional third parameter. The enclosure character is double quote, unless it is specified. Delimiter and enclosure cannot be null and only first character is used when they are specified.

Fp must be a valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen()

Length must be greater than the longest line to be found in the CSV file (allowing for trailing line-end characters).

fgetcsv() returns FALSE on error, including end of file.

Huomaa: A blank line in a CSV file will be returned as an array comprising a single NULL field, and will not be treated as an error.

enclosure is added from PHP 4.3.0.

Esimerkki 1. fgetcsv() example - Read and print entire contents of a CSV file

$row = 1;
$fp = fopen ("test.csv","r");
while ($data = fgetcsv ($fp, 1000, ",")) {
    $num = count ($data);
    print "<p> $num fields in line $row: <br>";
    $row++;
    for ($c=0; $c < $num; $c++) {
        print $data[$c] . "<br>";
    }
}
fclose ($fp);
User Contributed Notes
fgetcsv
add a note about notes
There are no user contributed notes for this page.
previousfgetcfgetsnext
Last updated: Tue, 28 May 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST