Tjerk Meesters wrote on 19/11/2014 12:20:
Hi list,

As I was fiddling with CSV data reading and writing I noticed that fgetcsv() is 
inherently incompatible with fputcsv() when it comes to the enclosure escape 
character that’s used.

Example: http://3v4l.org/LHEZj

The above example code demonstrates how, by default, fputcsv() encodes a 
backslash as is but fgetcsv() will treat that same backslash as the enclosure 
escape character as well as the enclosure character itself; this is rather 
surprising behaviour and imho unnecessarily complicated.

I would suggest changing the behaviour in such a way that:
a) the default enclosure escape character for fgetcsv() is a double quote.
b) fgetcsv() only treats the escape character as … an escape character.

Due to the kind of change BC can’t be maintained, so I’d propose this change 
for PHP 7.

If anyone has violent objections to the above, or thinks that an RFC should be 
drawn up, do let me know … otherwise I’ll commit the change into master by next 
week or so.


Best,
  Tjerk

If I remember rightly, some of the escaping behaviour is actually incompatible with MS Excel (I believe 2000 was the current version when I tested) as well, which struck me as rather unfortunate.

However, I'm always a bit wary of subtle breaking changes like this, so we need to be sure we definitely get it right this time, and that there are documented options to both functions which emulate the old behaviour.

Regards,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to