|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-07-13 09:10 UTC] dmitry dot dulepov at gmail dot com
Description:
------------
Putting a space around the separator *and* using quotes around fields adds
spaces to the field. The following line:
"123" , "456"
should produce:
"123" and "456"
but it makes:
"123 " and " 456".
In the RFC4180 the specification suggests that if the field contains quotes,
only the text inside quotes is the content of the field. Here is the formal
gramma:
record = field *(COMMA field)
field = (escaped / non-escaped)
escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTE
non-escaped = *TEXTDATA
Thus spaces should appear in field only if the field is not quoted.
Test script:
---------------
print_r(str_getcsv('"123" , "456" ', ',', '"'))
Expected result:
----------------
array(
0 => "123",
1 => "456",
)
Actual result:
--------------
array(
0 => "123 ",
1 => "456 ",
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 00:00:01 2025 UTC |
str_getcsv is a conversion tool and not an input validator. Any invalid input is surely not going to work correctly and I do not think it is good practice to account for bad input b/c it would cause extra processing time when it is not needed. If the input were: var_dump(str_getcsv('"123" a , "456" ', ',', '"')) what would you expect str_getcsv to do?