Bug #55763 [Opn]: str_getcsv incorrectly handles line-breaks inside fields

From: Date: Thu, 22 Sep 2011 16:45:02 +0000
Subject: Bug #55763 [Opn]: str_getcsv incorrectly handles line-breaks inside fields
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-163791@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55763&edit=1 ID: 55763 User updated by: talk at alexmingoia dot com Reported by: talk at alexmingoia dot com Summary: str_getcsv incorrectly handles line-breaks inside fields Status: Open Type: Bug Package: Strings related Operating System: OS X 10.6 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Sorry... expected output should be array(4) { [0]=> string(15) "Name,Desc,Email" [1]=> string(4) "Alex" [2]=> string(18) "Is a PHP developer " [3]=> string(16) "alex@example.com" } Previous Comments: ------------------------------------------------------------------------ [2011-09-22 16:41:15] talk at alexmingoia dot com Description: ------------ RFC4180 states that fields can contain line breaks as long as they are properly enclosed by double-quotes. str_getcsv treats line-breaks inside of enclosed fields as new records in the CSV. Setting 'auto_detect_line_ending' to TRUE or using "\r\n" instead of "\n" still produces incorrect results. Test script: --------------- $csv = file_get_contents('test.csv'); $csvArray = str_getcsv($csv, "\n"); var_dump($csvArray); Expected result: ---------------- array(4) { [0]=> string(15) "Name,Desc,Email" [1]=> string(4) "Alex" [2]=> string(18) "Is a PHP developer" [3]=> string(16) "alex@example.com" } Actual result: -------------- array(4) { [0]=> string(15) "Name,Desc,Email" [1]=> string(14) "Alex,"Is a PHP" [2]=> string(9) "developer" [3]=> string(17) ",alex@example.com" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55763&edit=1

« previous php.bugs (#163791) next »