|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-18 12:51 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 16:00:01 2025 UTC |
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 BO1`11519`112733`CELTIC002`2002/01/02````D.W.`Marilyn````````2`2``2`1225`10039 BO1`11520`=VARIOUS`HILL 1`2002/01/18````Various`Marilyn````````36``36`36`1225`VARIOUS BO1`11521`+VARIOUS`HILL 1`2002/01/14````Various`Marilyn````````32``32`32`1225`VARIOUS BO1`11522`\\VARIOUS`HILL 1`2002/01/14````Various`Marilyn````````133``133`133`1225`VARIOUS BO1`11523`113027`FRAIKIN006`2002/01/02````S.W.`Marilyn```````10`1``1`1`1225`AAN124 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 1`2002/01/14````Various`Marilyn````````133``133`133`1225`VARIOUS BO1`11523`113027`FRAIKIN006`2002/01/02````S.W.`Marilyn```````10`1``1`1`1225`AAN124 1