1--TEST--
2various fputcsv() functionality tests
3--CREDITS--
4Lee Leathers <leeleathers@gmail.com>
5--FILE--
6<?php
7
8$list = array (
9  0 => 'aaa,bbb',
10  1 => 'aaa,"bbb"',
11  2 => '"aaa","bbb"',
12  3 => 'aaa,bbb',
13  4 => '"aaa",bbb',
14  5 => '"aaa",   "bbb"',
15  6 => ',',
16  7 => 'aaa,',
17  8 => ',"aaa"',
18  9 => '"",""',
19  10 => '"""""",',
20  11 => '""""",aaa',
21  12 => 'aaa,bbb   ',
22  13 => 'aaa,"bbb   "',
23  14 => 'aaa"aaa","bbb"bbb',
24  15 => 'aaa"aaa""",bbb',
25  16 => 'aaa,"/"bbb,ccc',
26  17 => 'aaa"/"a","bbb"',
27  18 => '"/"","aaa"',
28  19 => '"/""",aaa',
29);
30
31$file = __DIR__ . '/fputcsv_variation15.csv';
32@unlink($file);
33
34$fp = fopen($file, "w");
35foreach ($list as $v) {
36    fputcsv($fp, explode(',', $v), ',', '"', '/');
37}
38fclose($fp);
39
40$res = file($file);
41foreach($res as &$val)
42{
43    $val = substr($val, 0, -1);
44}
45echo '$list = ';var_export($res);echo ";\n";
46
47$fp = fopen($file, "r");
48$res = array();
49while($l=fgetcsv($fp, 0, ',', '"', '/'))
50{
51    $res[] = join(',',$l);
52}
53fclose($fp);
54
55echo '$list = ';var_export($res);echo ";\n";
56
57@unlink($file);
58
59?>
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