Annotation of embedaddon/php/ext/standard/tests/file/fputcsv.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: various fputcsv() functionality tests
                      3: --FILE--
                      4: <?php
                      5: 
                      6: $list = array (
                      7:   0 => 'aaa,bbb',
                      8:   1 => 'aaa,"bbb"',
                      9:   2 => '"aaa","bbb"',
                     10:   3 => 'aaa,bbb',
                     11:   4 => '"aaa",bbb',
                     12:   5 => '"aaa",   "bbb"',
                     13:   6 => ',',
                     14:   7 => 'aaa,',
                     15:   8 => ',"aaa"',
                     16:   9 => '"",""',
                     17:   10 => '"""""",',
                     18:   11 => '""""",aaa',
                     19:   12 => 'aaa,bbb   ',
                     20:   13 => 'aaa,"bbb   "',
                     21:   14 => 'aaa"aaa","bbb"bbb',
                     22:   15 => 'aaa"aaa""",bbb',
                     23:   16 => 'aaa,"\\"bbb,ccc',
                     24:   17 => 'aaa"\\"a","bbb"',
                     25:   18 => '"\\"","aaa"',
                     26:   19 => '"\\""",aaa',
                     27: );
                     28: 
                     29: $file = dirname(__FILE__) . 'fgetcsv.csv';
                     30: @unlink($file);
                     31: 
                     32: $fp = fopen($file, "w");
                     33: foreach ($list as $v) {
                     34:        fputcsv($fp, explode(',', $v));
                     35: }
                     36: fclose($fp);
                     37: 
                     38: $res = file($file);
                     39: foreach($res as &$val)
                     40: {
                     41:        $val = substr($val, 0, -1);
                     42: }
                     43: echo '$list = ';var_export($res);echo ";\n";
                     44: 
                     45: $fp = fopen($file, "r");
                     46: $res = array();
                     47: while($l=fgetcsv($fp))
                     48: {
                     49:        $res[] = join(',',$l);
                     50: }
                     51: fclose($fp);
                     52: 
                     53: echo '$list = ';var_export($res);echo ";\n";
                     54: 
                     55: @unlink($file);
                     56: 
                     57: ?>
                     58: ===DONE===
                     59: <?php exit(0); ?>
                     60: --EXPECT--
                     61: $list = array (
                     62:   0 => 'aaa,bbb',
                     63:   1 => 'aaa,"""bbb"""',
                     64:   2 => '"""aaa""","""bbb"""',
                     65:   3 => 'aaa,bbb',
                     66:   4 => '"""aaa""",bbb',
                     67:   5 => '"""aaa""","   ""bbb"""',
                     68:   6 => ',',
                     69:   7 => 'aaa,',
                     70:   8 => ',"""aaa"""',
                     71:   9 => '"""""",""""""',
                     72:   10 => '"""""""""""""",',
                     73:   11 => '"""""""""""",aaa',
                     74:   12 => 'aaa,"bbb   "',
                     75:   13 => 'aaa,"""bbb   """',
                     76:   14 => '"aaa""aaa""","""bbb""bbb"',
                     77:   15 => '"aaa""aaa""""""",bbb',
                     78:   16 => 'aaa,"""\\"bbb",ccc',
                     79:   17 => '"aaa""\\"a""","""bbb"""',
                     80:   18 => '"""\\"""","""aaa"""',
                     81:   19 => '"""\\"""""",aaa',
                     82: );
                     83: $list = array (
                     84:   0 => 'aaa,bbb',
                     85:   1 => 'aaa,"bbb"',
                     86:   2 => '"aaa","bbb"',
                     87:   3 => 'aaa,bbb',
                     88:   4 => '"aaa",bbb',
                     89:   5 => '"aaa",   "bbb"',
                     90:   6 => ',',
                     91:   7 => 'aaa,',
                     92:   8 => ',"aaa"',
                     93:   9 => '"",""',
                     94:   10 => '"""""",',
                     95:   11 => '""""",aaa',
                     96:   12 => 'aaa,bbb   ',
                     97:   13 => 'aaa,"bbb   "',
                     98:   14 => 'aaa"aaa","bbb"bbb',
                     99:   15 => 'aaa"aaa""",bbb',
                    100:   16 => 'aaa,"\\"bbb,ccc',
                    101:   17 => 'aaa"\\"a","bbb"',
                    102:   18 => '"\\"","aaa"',
                    103:   19 => '"\\""",aaa',
                    104: );
                    105: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>