[php-src] Issue #8649: fgetcsv() cause wrong parse on specific UTF-8 BOM encoded CSV

From: Date: Sat, 28 May 2022 08:38:17 +0000
Subject: [php-src] Issue #8649: fgetcsv() cause wrong parse on specific UTF-8 BOM encoded CSV
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241613@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8649 Author: yui-Kitamura ### Description When the CSV file that its the first value is empty and they are quoted with the double quotation mark, PHP function fgetcsv parses the double quotation mark as a string value , only when the file was encoded with UTF-8 BOM. Use the CSV file saved encoding with UTF-8 BOM. ```csv "","key","key2" "name","val","val2" ``` *The FIRST CELL is EMPTY The following code: ```php <?php $csvFile = fopen("utf8Bom.csv", "r"); while($line = fgetcsv($csvFile)) { for($idx = 0, $size = count($line); $idx < $size; $idx++ ){ echo "[". $line[$idx] ."]"; } echo "<br>"; } fclose($csvFile); ?> ``` Resulted in this output: ``` [""][key][key2] [name][val][val2] ``` The first cell has "" as a value. But I expected this output instead: ``` [][key][key2] [name][val][val2] ``` NOTE: the CSV file that encoded with SJIS and the same values parses the first "" empty cell as a empty value. It's collect. Environment: IIS on WinServer2022 Please test on PHP 8.x who can use it.. ### PHP Version PHP 7.4.29 ### Operating System Windows Server 2022

« previous php.bugs (#241613) next »