From: programmer at tklee dot com Operating system: Linux PHP version: 5.1.4 PHP Bug Type: Feature/Change Request Bug description: field enclosure behavior in fputcsv
Description: ------------ Regarding the field enclosure parameter in fputcsv... 1. It's unrealistic to require the field enclosure to be one character because it's very common to have "empty string" as the field delimiter (especially when TAB is used as field delimiter). I tried to use "\0" as the field enclosure, hoping that'd be interpreted as an empty string, but fputcsv translated it into literal. 2. fputcsv wrongly adds the field enclosures whenever a field contains a space. The expected behavior should be adding the field enclosures when a field contains a field delimiter. Reproduce code: --------------- /* test_in.csv has only one line: $line = "field 0\tfield_1\tfield 2\n"; */ $fh_in=fopen("test_in.csv","r"); $fh_out=fopen("test_out.csv","w"); // since "" is not accepted as the 4th parameter, I use "\0" instead $fields = fgetcsv($fh_in, 0, "\t", "\0"); fputcsv($fh_out, $fields, "\t", "\0"); close($fh_in); close($fh_out); Expected result: ---------------- /* One would expect to see in test_out.csv : $line = "field 0\tfield_1\tfield_2\n"; */ Actual result: -------------- /* However, the result shows: $line = "\0field 0\0\tfield_1\t\0field 2\0\n"; Unexpected: 1. Since space is not the field delimiter, there is no point of using the field enclosure. 2. Empty enclosure is very common and should be accepted. */ -- Edit bug report at http://bugs.php.net/?id=38301&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38301&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38301&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38301&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38301&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38301&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38301&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38301&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38301&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38301&r=support Expected behavior: http://bugs.php.net/fix.php?id=38301&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38301&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38301&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38301&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38301&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38301&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38301&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38301&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38301&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38301&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38301&r=mysqlcfg