3v4l.org

run code in 300+ PHP versions simultaneously
<?php $crlf = chr(13) . chr(10); $cr = chr(13); $delimiter = '|'; // 7 rows, 5th row has CR linebreak inside $lines = [ 'A', 'a', 'C15|C18|C21|C36|C42|C45|C48|C51|C54|C60|C63|C66|C69|C72|C75|C81|C84|C90|C93|C96|C99|C102|C105|C108|C111', '02-DEC-19|02-DEC-19|707403|GUEST|||PPPPPP||||||RR||||RRSSIAN||FFFF|||||+1111-11-11-111|', '02-DEC-19|02-DEC-19|707404|GUEST|SDDDDD|ВВВВВВВВВВВВ|PPPPPP|СССССС|ПППППП||01.01.1111|M|RR|ППППП|"ПППППППП кккк' . $cr . '"|MISSING LINE CONTENTS|', 'FF_FFFF|FF_1', '|1', ]; $csv = implode($crlf, $lines); $filePath = tempnam(sys_get_temp_dir(), 'csv'); file_put_contents($filePath, $csv); $file = fopen($filePath, 'r'); //ini_set('auto_detect_line_endings', true); $rows = []; while (!feof($file)) { $row = fgetcsv($file, 0, $delimiter, '"', "\0"); if ($row === null) { print_r("NULL result found though `SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE` flags set.\n"); } else { $rows[] = implode($delimiter, $row); } } if (implode($crlf, $lines) !== implode($crlf, $rows)) { print_r("Error! Expected:\n"); print_r($lines); print_r("Parsed as:\n"); print_r($rows); } else { print_r("Passed."); }
Output for 7.1.26 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Error! Expected: Array ( [0] => A [1] => a [2] => C15|C18|C21|C36|C42|C45|C48|C51|C54|C60|C63|C66|C69|C72|C75|C81|C84|C90|C93|C96|C99|C102|C105|C108|C111 [3] => 02-DEC-19|02-DEC-19|707403|GUEST|||PPPPPP||||||RR||||RRSSIAN||FFFF|||||+1111-11-11-111| [4] => 02-DEC-19|02-DEC-19|707404|GUEST|SDDDDD|ВВВВВВВВВВВВ|PPPPPP|СССССС|ПППППП||01.01.1111|M|RR|ППППП|"ПППППППП кккк "|MISSING LINE CONTENTS| [5] => FF_FFFF|FF_1 [6] => |1 ) Parsed as: Array ( [0] => A [1] => a [2] => C15|C18|C21|C36|C42|C45|C48|C51|C54|C60|C63|C66|C69|C72|C75|C81|C84|C90|C93|C96|C99|C102|C105|C108|C111 [3] => 02-DEC-19|02-DEC-19|707403|GUEST|||PPPPPP||||||RR||||RRSSIAN||FFFF|||||+1111-11-11-111| [4] => 02-DEC-19|02-DEC-19|707404|GUEST|SDDDDD|ВВВВВВВВВВВВ|PPPPPP|СССССС|ПППППП||01.01.1111|M|RR|ППППП|ПППППППП кккк |MISSING LINE CONTENTS| [5] => FF_FFFF|FF_1 [6] => |1 )

preferences:
183.13 ms | 405 KiB | 180 Q