3v4l.org

run code in 300+ PHP versions simultaneously
<?php # some text strings for digging the broken fputcsv() issue of php5-7(current) # .. and maybe related tests broken too due to using fgetcsv() for validation resulting # in reverting hiddenly "fixing a bad csv output # --> compare the output strings direct in php-src tests instead using fgetcsv() maybe? # related rfc4180: https://tools.ietf.org/html/rfc4180 $row = array(); $row[] = 'test \" test'; # should be "test \"" test",... in the normal csv $row[] = "bbb\80 b"; $row[] = ''; # ..,,.. $row[] = '""'; # either ..,"""""", $row[] = '"c c\"'; # should be ..,"""c c\""" in the normal csv $row[] = '\0'; $row[] = "\0"; $row[] = "\80\0"; $row[] = 'lulu\0'; $row[] = "\0 lala"; $row[] = '💩'; # pile of poop unicode $row[] = 'colend'; $fp = fopen('php://memory', 'w+'); fputcsv($fp, $row); rewind($fp); print_r(stream_get_contents($fp)); fclose($fp); $fp2 = fopen('php://memory', 'w+'); # This should be the default parameters for fputcsv, IMHO # But it is not working at least up to 2017-10-07 fputcsv($fp2, $row, ',', '"','"'); rewind($fp2); print_r(stream_get_contents($fp2)); fclose($fp2); $fp3 = fopen('php://memory', 'w+'); fputcsv($fp3, $row, ',', '"',"\0"); rewind($fp3); print_r(stream_get_contents($fp3)); fclose($fp3); $fp4 = fopen('php://memory', 'w+'); # just use a normal char as just for comparing with the other variants fputcsv($fp4, $row, ',', '"','X'); rewind($fp4); print_r(stream_get_contents($fp4)); fclose($fp4); # !Results should be compared binary too as some chars maybe are not printed or cut, for instance with hexdump -C

preferences:
44.79 ms | 402 KiB | 5 Q