3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php # some text strings for digging the broken fputcsv() issue of php5-7(current) # .. and maybe related tests broken too due too using bad default fgetcsv() behavior # related rfc4180: https://tools.ietf.org/html/rfc4180 $row = array(); $row[] = 'test \" test'; # should be "test \"" test" in the normal csv $row[] = 'bbb'; $row[] = ''; # ..,,.. $row[] = '""'; # either ..,"""""", $row[] = '"c c\"'; # should be ..,"""c c\""" in the normal csv $row[] = '\0'; $row[] = "\0"; $row[] = 'lulu\0'; $row[] = "\0 lala"; $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
based on HBs6T
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
"test \" test",bbb,,"""""","""c c\"","\0",,"lulu\0"," lala",colend "test \" test",bbb,,"""",""c c\"",\0,,lulu\0," lala",colend "test \"" test",bbb,,"""""","""c c\""",\0,"",lulu\0," lala",colend "test \"" test",bbb,,"""""","""c c\""",\0,,lulu\0," lala",colend