PHP Classes


Recommend this page to a friend!

      CSV Handler  >  All threads  >  fgetcsv  >  (Un) Subscribe thread alerts  
Summary:fgetcsv seems to truncate empty columns on the end
Author:Richard Wilson
Date:2005-10-03 02:30:43
Update:2005-10-03 10:14:14

  1. fgetcsv   Reply   Report abuse  
Picture of Richard Wilson Richard Wilson - 2005-10-03 02:30:43
I exported my phone list from Outlook in CSV format.
With CSVHandler, I got undefined index errors on line 37. I investigated and found that fgetcsv did not get the right number of columns. To fix this, I changed the following code:
while ($DataLine = fgetcsv ($fp, 3000, $this->Separator)) {
while ($DataLine = fgetcsv ($fp, 0, $this->Separator)) {
if ($i < count($DataLine))
} else

It seems to work now.

  2. Re: fgetcsv   Reply   Report abuse  
Picture of Andreas Mueller Andreas Mueller - 2005-10-03 10:14:14 - In reply to message 1 from Richard Wilson
Hi Richard.

Thanks for that information.
Your change does of course work as it provides correct definition for empty cells.

I'll use it for the next version. Just never occured to me that any program would write such truncated csv-files. Standard would require to generate an empty field to be exported as just a delimiter, and depending on settings a set of "" in case of a text field (wich is another csv-feature I have not taken care of, those are just removed :-)


For more information send a message to info at phpclasses dot org.