[dev] Re: [turba] CSV EXPORT double quotes problem

Michael Cochrane mike@graftonhall.co.nz
Wed, 31 Jul 2002 17:10:27 +0100


This is part of a big CSV issue i discovered last night. It is actually more
accurate to just double quote the whole lot and not worry about what appears
between those (including other double quotes). 

I have a patch for the CSV import coming with the import/export code for mnemo
in about 20 mins that uses the PEAR CSV class which handles multiline imports
correctly.

- Mike :-)


Quoting Rong-en Fan <rafan@infor.org>:

> Hi all,
> 
> I'm using Horde 2.1 and Turba 1.1 on PHP 4.2.2, all settings are default
> except something like sql db, user, password, etc.
> 
> The CSV exported from Turba has a little problem while there are double
> quotes in it. The output will be something like ...,"\"",... , but
> the CSV that generated by MS Excel 2000 / Outlook Express 6 and CSV file
> format found from http://www.wotsit.org/download.asp?f=csv both say that
> if any double quotes in the source data, the encapsulation in CSV should
> be doubled up, i.e. " (source data) ==> ...,"""",... Also, if we import
> the CSV file exported by Turba, Turba will interpret the fields incorrectly.
> (Try it yourself :p)
> 
> The problem lays in horde/lib/Data.php, Line 113
> 
>     $export .= '"' . addslashes($cell) . '"';
> 
> addslashes($cell) exists since the initial version 1.1 of Data.php
> I wonder why there is addslashes(), my own patch is
> 
> -                    $export .= '"' . addslashes($cell) . '"';
> +                    $cell = preg_replace ("/\"/", "\"\"", $cell);
> +                    $export .= '"' . $cell . '"';
> 
> Finally, is there any strong reason that we have to use addslases($cell),
> instead just leave $cell along and doubled double quotes up?
> 
> Regards,
> Rong-en Fan
> 
> -- 
> Turba mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: turba-unsubscribe@lists.horde.org


-- 
In dreams and in love there are no impossibilities. - Janos Arnay
signature from Siglets.com

-------------------------------------------------------------------------
This mail sent from Mike's CVS HEAD install of IMP: http://horde.org/imp/