> On 20 Nov 2014, at 00:26, Christoph Becker <cmbecke...@gmx.de> wrote:
> 
> Tjerk Meesters wrote:
> 
>> 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.
> 
> Are you aware of <https://bugs.php.net/bug.php?id=50686>?  It seems this
> very inconsistency has been reported a few years ago, but has been
> tagged as "Wont fix" back then.

Actually that bug report seems to suggest that fputcsv() uses backslash to 
encode enclosure characters, but AFAICT it doesn’t.

And then there are bug reports like https://bugs.php.net/bug.php?id=67566 which 
were fixed but really just made the situation worse =(

> 
> <https://bugs.php.net/bug.php?id=38929> also seems to deal with this
> inconsistency, and had been tagged as "Not a bug".
> 
> So maybe an RFC is appropriate?

Yeah, I didn’t realise the can of worms until I opened it; I’ll round up all 
the bug reports and run them against whatever RFC I can get my hands on.

PS: Favourite quote from the semi-authoritative spec of Perl_CSV: 
http://rath.ca/Misc/Perl_CSV/CSV-2.0.html#csv:

> Given that the essence of CSV files is simplicity, I have decided to reject 
> all escape and escaped characters with the exception of quoation marks 
> appearing within quotation marks …

Good times :)

> 
> -- 
> Christoph M. Becker


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

Reply via email to