note 98502 modified in function.fgetcsv by danbrown

From: Date: Fri, 25 Jun 2010 15:22:48 +0000
Subject: note 98502 modified in function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170457@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: <?php 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; --was-- 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; http://php.net/manual/en/function.fgetcsv.php

« previous php.notes (#170457) next »