Name
fgetcsv
Synopsis
array fgetcsv(inthandle
, intlength
[, stringdelimiter
[, stringenclosure
]])
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 supplied,
delimiter
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). 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);
Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.