O'Reilly logo

Programming PHP, 3rd Edition by Peter MacIntyre, Kevin Tatroe, Rasmus Lerdorf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

fgetcsv

Synopsis

array fgetcsv(resource handle[, int length[, string delimiter[, string enclosure
    [, string escape ]]]])

Reads the next line from the file referenced by handle and parses the line as a comma-separated values (CSV) line. The longest line to read is given by length. If delimiter is supplied, it is used to delimit the values for the line instead of commas. If supplied, enclosure is a single character that is used to enclose values (by default, the double quote character "). escape sets the escape character to use; the default is backslash \; one character only can be specified. For example, to read and display all lines from a file containing tab-separated values, use:

$fp = fopen("somefile.tab", "r");

while($line = fgetcsv($fp, 1024, "\t")) {
  print "<p>" . count($line) . "fields:</p>";
  print_r($line);
}
fclose($fp);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required