3v4l.org

run code in 300+ PHP versions simultaneously
<?php # some text strings for digging the broken fputcsv() 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
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
"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
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 "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

preferences:
208.92 ms | 402 KiB | 291 Q