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 = dirname(__FILE__) . 'fgetcsv.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===DONE===
61<?php exit(0); ?>
62--EXPECT--
63$list = array (
64  0 => 'aaa,bbb',
65  1 => 'aaa,"""bbb"""',
66  2 => '"""aaa""","""bbb"""',
67  3 => 'aaa,bbb',
68  4 => '"""aaa""",bbb',
69  5 => '"""aaa""","   ""bbb"""',
70  6 => ',',
71  7 => 'aaa,',
72  8 => ',"""aaa"""',
73  9 => '"""""",""""""',
74  10 => '"""""""""""""",',
75  11 => '"""""""""""",aaa',
76  12 => 'aaa,"bbb   "',
77  13 => 'aaa,"""bbb   """',
78  14 => '"aaa""aaa""","""bbb""bbb"',
79  15 => '"aaa""aaa""""""",bbb',
80  16 => 'aaa,"""/"bbb",ccc',
81  17 => '"aaa""/"a""","""bbb"""',
82  18 => '"""/"""","""aaa"""',
83  19 => '"""/"""""",aaa',
84);
85$list = array (
86  0 => 'aaa,bbb',
87  1 => 'aaa,"bbb"',
88  2 => '"aaa","bbb"',
89  3 => 'aaa,bbb',
90  4 => '"aaa",bbb',
91  5 => '"aaa",   "bbb"',
92  6 => ',',
93  7 => 'aaa,',
94  8 => ',"aaa"',
95  9 => '"",""',
96  10 => '"""""",',
97  11 => '""""",aaa',
98  12 => 'aaa,bbb   ',
99  13 => 'aaa,"bbb   "',
100  14 => 'aaa"aaa","bbb"bbb',
101  15 => 'aaa"aaa""",bbb',
102  16 => 'aaa,"/"bbb,ccc',
103  17 => 'aaa"/"a","bbb"',
104  18 => '"/"","aaa"',
105  19 => '"/""",aaa',
106);
107===DONE===
108