xref: /php-src/ext/standard/tests/file/fgetcsv.phpt (revision f756b96e)
1--TEST--
2various fgetcsv() functionality tests
3--FILE--
4<?php
5    $list = array(
6        'aaa,bbb',
7        'aaa,"bbb"',
8        '"aaa","bbb"',
9        'aaa,bbb',
10        '"aaa",bbb',
11        '"aaa",   "bbb"',
12        ',',
13        'aaa,',
14        ',"aaa"',
15        '"",""',
16        '"\\"","aaa"',
17        '"""""",',
18        '""""",aaa' . "\n",
19        '"\\""",aaa' . "\n",
20        'aaa,"\\"bbb,ccc' . "\n",
21        'aaa,bbb   ',
22        'aaa,"bbb   "',
23        'aaa"aaa","bbb"bbb',
24        'aaa"aaa""",bbb',
25        'aaa"\\"a","bbb"',
26        'aaa,"bbb' . "\n",
27        'aaa,"bbb',
28    );
29
30    $file = __DIR__ . '/fgetcsv.csv';
31    @unlink($file);
32    foreach ($list as $v) {
33        $fp = fopen($file, "w");
34        fwrite($fp, $v);
35        fclose($fp);
36
37        var_dump(fgetcsv(fopen($file, "r"), 1024, escape: "\\"));
38    }
39    @unlink($file);
40?>
41--EXPECT--
42array(2) {
43  [0]=>
44  string(3) "aaa"
45  [1]=>
46  string(3) "bbb"
47}
48array(2) {
49  [0]=>
50  string(3) "aaa"
51  [1]=>
52  string(3) "bbb"
53}
54array(2) {
55  [0]=>
56  string(3) "aaa"
57  [1]=>
58  string(3) "bbb"
59}
60array(2) {
61  [0]=>
62  string(3) "aaa"
63  [1]=>
64  string(3) "bbb"
65}
66array(2) {
67  [0]=>
68  string(3) "aaa"
69  [1]=>
70  string(3) "bbb"
71}
72array(2) {
73  [0]=>
74  string(3) "aaa"
75  [1]=>
76  string(3) "bbb"
77}
78array(2) {
79  [0]=>
80  string(0) ""
81  [1]=>
82  string(0) ""
83}
84array(2) {
85  [0]=>
86  string(3) "aaa"
87  [1]=>
88  string(0) ""
89}
90array(2) {
91  [0]=>
92  string(0) ""
93  [1]=>
94  string(3) "aaa"
95}
96array(2) {
97  [0]=>
98  string(0) ""
99  [1]=>
100  string(0) ""
101}
102array(2) {
103  [0]=>
104  string(2) "\""
105  [1]=>
106  string(3) "aaa"
107}
108array(2) {
109  [0]=>
110  string(2) """"
111  [1]=>
112  string(0) ""
113}
114array(1) {
115  [0]=>
116  string(7) """,aaa
117"
118}
119array(1) {
120  [0]=>
121  string(8) "\"",aaa
122"
123}
124array(2) {
125  [0]=>
126  string(3) "aaa"
127  [1]=>
128  string(10) "\"bbb,ccc
129"
130}
131array(2) {
132  [0]=>
133  string(3) "aaa"
134  [1]=>
135  string(6) "bbb   "
136}
137array(2) {
138  [0]=>
139  string(3) "aaa"
140  [1]=>
141  string(6) "bbb   "
142}
143array(2) {
144  [0]=>
145  string(8) "aaa"aaa""
146  [1]=>
147  string(6) "bbbbbb"
148}
149array(2) {
150  [0]=>
151  string(10) "aaa"aaa""""
152  [1]=>
153  string(3) "bbb"
154}
155array(2) {
156  [0]=>
157  string(8) "aaa"\"a""
158  [1]=>
159  string(3) "bbb"
160}
161array(2) {
162  [0]=>
163  string(3) "aaa"
164  [1]=>
165  string(4) "bbb
166"
167}
168array(2) {
169  [0]=>
170  string(3) "aaa"
171  [1]=>
172  string(3) "bbb"
173}
174