[php-src] Issue #10566: str_getcsv won't work correctly in some special cases

From: Date: Sat, 11 Feb 2023 13:24:02 +0000
Subject: [php-src] Issue #10566: str_getcsv won't work correctly in some special cases
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243710@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10566 Author: porthd ### Description The function should not rebuild the string-annotation in the CSV-String by using the commas, if str_getcsv is used in the first step of the small algorithm. The following code is motivated by the example of [durik at 3ilab dot net ](https://www.php.net/manual/en/function.str-getcsv.php#101888): He mentioned: "... Why not use explode() instead of str_getcsv() to parse rows? Because explode() would not treat possible enclosured parts of string or escaped characters correctly." ```php <?php $string =<<<DOMTEST "PHP, Java","Python" "PHP2, Java2","Python" "PHP3, Java3","Python" DOMTEST; $data = str_getcsv($string, "\n" ); foreach ($data as &$row) { $row = str_getcsv($row, ','); } var_dump($data); ``` Resulted in this output: ``` array(3) { [0]=> array(3) { [0]=> string(3) "PHP" [1]=> string(5) " Java" [2]=> string(6) "Python" } [1]=> array(3) { [0]=> string(4) "PHP2" [1]=> string(6) " Java2" [2]=> string(6) "Python" } [2]=> &array(3) { [0]=> string(4) "PHP3" [1]=> string(6) " Java3" [2]=> string(6) "Python" } } ``` But I expected this output instead: ``` array(3) { [0]=> array(2) { [0]=> string(8) "PHP, Java" [1]=> string(6) "Python" } [1]=> array(2) { [0]=> string(10) "PHP2, Java2" [1]=> string(6) "Python" } [2]=> &array(2) { [0]=> string(10) "PHP3, Java3" [1]=> string(6) "Python" } } ``` ### PHP Version 8.2.1 ### Operating System _No response_

« previous php.bugs (#243710) next »