<?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
- 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- "test \" test","bbb\80 b",,"""""","""c c\"","\0", ,"\80 ","lulu\0"," lala",💩,colend
"test \" test","bbb\80 b",,"""",""c c\"",\0, ,\80 ,lulu\0," lala",💩,colend
"test \"" test","bbb\80 b",,"""""","""c c\""",\0," ","\80 ",lulu\0," lala",💩,colend
"test \"" test","bbb\80 b",,"""""","""c c\""",\0, ,\80 ,lulu\0," lala",💩,colend
preferences:
230.74 ms | 404 KiB | 287 Q