note 98502 added to function.fgetcsv
| From: | carloshNOSPAM at 4sconsult dot com | Date: | Sat, 19 Jun 2010 00:42:06 +0000 |
| Subject: | note 98502 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170258@lists.php.net to get a copy of this message | ||
For my surprise this function using 5.3.2 on windows now when it reads an empty line it returns
FALSE instead of an empty array as the previous versions. This affect code that do not check the
result and tries something like this:
while(!feof($fp)){
$line=fgetcsv($fp,4096,',','"');
foreach($line as $key=>$value){
....
}
}
when it was empty array this foreach pass ok but now with FALSE gives this error:
Invalid argument supplied for foreach()
Anyways, it is good idea to check what you getting before process further. This following line will
fix the existing code.
if(!$line=fgetcsv($fp,4096,',','"') continue;
----
Server IP: 69.147.83.197
Probable Submitter: 65.95.156.15
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- https://master.php.net/note/edit/98502
Del: integrated -- https://master.php.net/note/delete/98502/integrated
Del: useless -- https://master.php.net/note/delete/98502/useless
Del: bad code -- https://master.php.net/note/delete/98502/bad+code
Del: spam -- https://master.php.net/note/delete/98502/spam
Del: non-english -- https://master.php.net/note/delete/98502/non-english
Del: in docs -- https://master.php.net/note/delete/98502/in+docs
Del: other reasons-- https://master.php.net/note/delete/98502
Reject -- https://master.php.net/note/reject/98502
Search -- https://master.php.net/manage/user-notes.php