#38496 [Opn->Csd]: fgetcsv() doesn't report delimiter/enclosure greater than 1 char like fputcsv.

From: Date: Fri, 18 Aug 2006 12:51:18 +0000
Subject: #38496 [Opn->Csd]: fgetcsv() doesn't report delimiter/enclosure greater than 1 char like fputcsv.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-101018@lists.php.net to get a copy of this message
ID: 38496 Updated by: tony2001@php.net Reported By: RQuadling at GMail dot com -Status: Open +Status: Closed -Bug Type: Streams related +Bug Type: Feature/Change Request Operating System: Windows XP SP2 PHP Version: 5CVS-2006-08-18 (snap) New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2006-08-18 10:33:10] RQuadling at GMail dot com Description: ------------ Hi. The issue was initially caught when I used '\t' rather than "\t". The source for fputcsv reports notices when you use a delimiter or an enclosure of > 1 character. But fgetcsv doesn't report this. The following patch should fix this. Index: file.c =================================================================== RCS file: /repository/php-src/ext/standard/file.c,v retrieving revision 1.449 diff -u -r1.449 file.c --- file.c 16 Jul 2006 15:54:25 -0000 1.449 +++ file.c 18 Aug 2006 10:30:51 -0000 @@ -2081,6 +2081,8 @@ if (delimiter_str_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); RETURN_FALSE; + } else if (delimiter_str_len > 1) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "delimiter must be a single character"); } /* use first character from string */ @@ -2091,6 +2093,8 @@ if (enclosure_str_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); RETURN_FALSE; + } else if (enclosure_str_len > 1) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "enclosure must be a single character"); } /* use first character from string */ enclosure = enclosure_str[0]; Reproduce code: --------------- <?php error_reporting(E_ALL); ++$dummy; // Proof of notices working. // Store CSV like data in temporary file. $fp = tmpfile(); // Real data I've been given - yeuch! fwrite($fp, <<< END_DATA BO111519112733CELTIC0022002/01/02```D.W.Marilyn```````22`21225`10039 BO111520=VARIOUS`HILL 12002/01/18``VariousMarilyn```````3636361225VARIOUS BO111521+VARIOUS`HILL 12002/01/14``VariousMarilyn```````3232321225VARIOUS BO111522\\VARIOUS`HILL 12002/01/14``VariousMarilyn```````1331331331225VARIOUS BO111523113027FRAIKIN0062002/01/02```S.W.Marilyn``````101`111225AAN124 END_DATA ); // Reset the file pointer. fseek($fp, 0, SEEK_SET); // Get data and report the number of $a = array ( fgetcsv($fp, 8192, '``'), // Expect notice - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "delimiter must be a single character") fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "enclosure must be a single character"); fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "enclosure must be a single character"); fgetcsv($fp, 8192, '`', '\t'), // Expect notice - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "enclosure must be a single character"); fgetcsv($fp, 8192, '`', "\t"), // Nothing wrong with this one. ); foreach($a as $b) { // Each row has 23 values. echo count($b), ' ', $b[2], "\n"; } fclose($fp); ?> Expected result: ---------------- Notices about enclosure or delimiter not being a single character like fputcsv Actual result: -------------- Notice: Undefined variable: dummy in C:\a.php on line 3 23 112733 23 =VARIOUS 23 +VARIOUS 3 VARIOUS`HILL 12002/01/14``VariousMarilyn```````1331331331225VARIOUS BO111523113027FRAIKIN0062002/01/02```S.W.Marilyn``````101`111225AAN124 1 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38496&edit=1

« previous php.bugs (#101018) next »