3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $csv = <<<'CSV' name, mail, age, bio john, j@ohn.com, 32, mary, mary@popp.com, 29, jeff, brid@ges.co, 47, "peterson, peter", peter@sson.com, 44, "loves: hobbies puzzles" CSV; $file = fopen('php://temp', 'rw'); var_dump($file); echo "\n"; fwrite($file, $csv); rewind($file); fpassthru($file); rewind($file); echo "\n\n"; function csv($file) { $header = null; while ($row = fgetcsv($file)) { $row = array_map('trim', $row); if ($header) { yield array_combine($header, $row); } else { $header = $row; } } } print_r(iterator_to_array(csv($file)));
Output for 5.6.0 - 7.2.6
resource(5) of type (stream) name, mail, age, bio john, j@ohn.com, 32, mary, mary@popp.com, 29, jeff, brid@ges.co, 47, "peterson, peter", peter@sson.com, 44, "loves: hobbies puzzles" Array ( [0] => Array ( [name] => john [mail] => j@ohn.com [age] => 32 [bio] => ) [1] => Array ( [name] => mary [mail] => mary@popp.com [age] => 29 [bio] => ) [2] => Array ( [name] => jeff [mail] => brid@ges.co [age] => 47 [bio] => ) [3] => Array ( [name] => peterson, peter [mail] => peter@sson.com [age] => 44 [bio] => loves: hobbies puzzles ) )