note 49321 added to function.fgetcsv
| From: | ramdac at ramdac dot org | Date: | Mon, 24 Jan 2005 05:40:03 +0000 |
| Subject: | note 49321 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83855@lists.php.net to get a copy of this message | ||
Be wary of Example #1 above.
If the file doesn't exist, the application will spit out data to STDOUT and could fill up /tmp
space if you're not careful. The output might will look like this:
PHP Warning: fgetcsv(): supplied argument is not a valid stream resource in...(your filename here)
To get around this, do the following:
<?
row = 1;
if(!$handle = fopen("test.csv", "r"))
{
print 'could not open file. quitting';
die;
}
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
?>
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49321
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49321&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49321&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49321&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49321&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49321&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49321&report=yes
Search -- http://master.php.net/manage/user-notes.php