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