#39538 [Opn->Csd]: fgetcsv can't handle starting newlines and trailing odd number of backslashes

From: Date: Wed, 22 Nov 2006 13:07:46 +0000
Subject: #39538 [Opn->Csd]: fgetcsv can't handle starting newlines and trailing odd number of backslashes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105307@lists.php.net to get a copy of this message
ID: 39538 Updated by: pajoye@php.net Reported By: mike at opendns dot com -Status: Open +Status: Closed Bug Type: *Directory/Filesystem functions Operating System: Linux, debian sarge PHP Version: 5.2.0 -Assigned To: +Assigned To: dsp 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. Fixed using a patch from David Soria Parra. Previous Comments: ------------------------------------------------------------------------ [2006-11-16 20:48:29] mike at opendns dot com Description: ------------ Two issues when reading in data from a CSV with fgetcsv(): If an element in a CSV file begins with a newline, fgetcsv() will think there's two newlines there. If an element in a CSV file ends with an odd number of trailing backslashes, it'll miss the enclosure character. This isn't a documentation problem - http://www.rfc-editor.org/rfc/rfc4180.txt Backslashes are not escape characters in CSV. Reproduce code: --------------- mikef@dev9:~$ cat -A /tmp/csv.tmp "$ two seperate issues: string begins with a newline, ends with odd number of backslashes \\\","and isnt the last element"$ mikef@dev9:~$ cat test_cvs.php <?php $tmp_file = '/tmp/csv.tmp'; $h = fopen($tmp_file, 'r'); $data_read_in = fgetcsv($h); fclose($h); var_dump($data_read_in); ?> Expected result: ---------------- mikef@dev9:~$ php test_cvs.php array(2) { [0]=> string(92) " two seperate issues: string begins with a newline, ends with odd number of backslasshes \\\" [1]=> string(25) "and isnt the last element" } Actual result: -------------- mikef@dev9:~$ php test_cvs.php array(1) { [0]=> string(121) " two seperate issues: string begins with a newline, ends with odd number of backslashes \\\",and isnt the last element"" } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39538&edit=1

« previous php.bugs (#105307) next »