1--TEST--
2Test fputcsv() : usage variations - with line without any csv fields
3--FILE--
4<?php
5/* Testing fputcsv() to write to a file when the field has no CSV format */
6
7echo "*** Testing fputcsv() : with no CSV format in the field ***\n";
8
9/* the array is with three elements in it. Each element should be read as
10   1st element is delimiter, 2nd element is enclosure
11   and 3rd element is csv fields
12*/
13
14$fields = array( array('water_fruit\n'),
15                array("water_fruit\n"),
16                array("")
17         );
18
19$file_path = __DIR__;
20$filename = "$file_path/fputcsv_variation10.tmp";
21
22$file_modes = array ("r+", "r+b", "r+t",
23                     "a+", "a+b", "a+t",
24                     "w+", "w+b", "w+t",
25                     "x+", "x+b", "x+t");
26
27$loop_counter = 1;
28foreach ($fields as $field) {
29  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
30
31    echo "\n-- file opened in $file_modes[$mode_counter] --\n";
32    // create the file and add the content with has csv fields
33    if ( strstr($file_modes[$mode_counter], "r") ) {
34      $file_handle = fopen($filename, "w");
35    } else {
36      $file_handle = fopen($filename, $file_modes[$mode_counter] );
37    }
38    if ( !$file_handle ) {
39      echo "Error: failed to create file $filename!\n";
40      exit();
41    }
42    $csv_field = $field;
43
44    // write to a file in csv format
45    var_dump( fputcsv($file_handle, $csv_field) );
46
47    // check the file pointer position and eof
48    var_dump( ftell($file_handle) );
49    var_dump( feof($file_handle) );
50    //close the file
51    fclose($file_handle);
52
53    // print the file contents
54    var_dump( file_get_contents($filename) );
55
56    //delete file
57    unlink($filename);
58  } //end of mode loop
59} // end of foreach
60
61echo "Done\n";
62?>
63--EXPECTF--
64*** Testing fputcsv() : with no CSV format in the field ***
65
66-- file opened in r+ --
67int(16)
68int(16)
69bool(false)
70string(16) ""water_fruit\n"
71"
72
73-- file opened in r+b --
74int(16)
75int(16)
76bool(false)
77string(16) ""water_fruit\n"
78"
79
80-- file opened in r+t --
81int(16)
82int(16)
83bool(false)
84string(%d) ""water_fruit\n"
85"
86
87-- file opened in a+ --
88int(16)
89int(16)
90bool(false)
91string(16) ""water_fruit\n"
92"
93
94-- file opened in a+b --
95int(16)
96int(16)
97bool(false)
98string(16) ""water_fruit\n"
99"
100
101-- file opened in a+t --
102int(16)
103int(16)
104bool(false)
105string(%d) ""water_fruit\n"
106"
107
108-- file opened in w+ --
109int(16)
110int(16)
111bool(false)
112string(16) ""water_fruit\n"
113"
114
115-- file opened in w+b --
116int(16)
117int(16)
118bool(false)
119string(16) ""water_fruit\n"
120"
121
122-- file opened in w+t --
123int(16)
124int(16)
125bool(false)
126string(%d) ""water_fruit\n"
127"
128
129-- file opened in x+ --
130int(16)
131int(16)
132bool(false)
133string(16) ""water_fruit\n"
134"
135
136-- file opened in x+b --
137int(16)
138int(16)
139bool(false)
140string(16) ""water_fruit\n"
141"
142
143-- file opened in x+t --
144int(16)
145int(16)
146bool(false)
147string(%d) ""water_fruit\n"
148"
149
150-- file opened in r+ --
151int(15)
152int(15)
153bool(false)
154string(15) ""water_fruit
155"
156"
157
158-- file opened in r+b --
159int(15)
160int(15)
161bool(false)
162string(15) ""water_fruit
163"
164"
165
166-- file opened in r+t --
167int(15)
168int(15)
169bool(false)
170string(%d) ""water_fruit
171"
172"
173
174-- file opened in a+ --
175int(15)
176int(15)
177bool(false)
178string(15) ""water_fruit
179"
180"
181
182-- file opened in a+b --
183int(15)
184int(15)
185bool(false)
186string(15) ""water_fruit
187"
188"
189
190-- file opened in a+t --
191int(15)
192int(15)
193bool(false)
194string(%d) ""water_fruit
195"
196"
197
198-- file opened in w+ --
199int(15)
200int(15)
201bool(false)
202string(15) ""water_fruit
203"
204"
205
206-- file opened in w+b --
207int(15)
208int(15)
209bool(false)
210string(15) ""water_fruit
211"
212"
213
214-- file opened in w+t --
215int(15)
216int(15)
217bool(false)
218string(%d) ""water_fruit
219"
220"
221
222-- file opened in x+ --
223int(15)
224int(15)
225bool(false)
226string(15) ""water_fruit
227"
228"
229
230-- file opened in x+b --
231int(15)
232int(15)
233bool(false)
234string(15) ""water_fruit
235"
236"
237
238-- file opened in x+t --
239int(15)
240int(15)
241bool(false)
242string(%d) ""water_fruit
243"
244"
245
246-- file opened in r+ --
247int(1)
248int(1)
249bool(false)
250string(1) "
251"
252
253-- file opened in r+b --
254int(1)
255int(1)
256bool(false)
257string(1) "
258"
259
260-- file opened in r+t --
261int(1)
262int(1)
263bool(false)
264string(%d) "
265"
266
267-- file opened in a+ --
268int(1)
269int(1)
270bool(false)
271string(1) "
272"
273
274-- file opened in a+b --
275int(1)
276int(1)
277bool(false)
278string(1) "
279"
280
281-- file opened in a+t --
282int(1)
283int(1)
284bool(false)
285string(%d) "
286"
287
288-- file opened in w+ --
289int(1)
290int(1)
291bool(false)
292string(1) "
293"
294
295-- file opened in w+b --
296int(1)
297int(1)
298bool(false)
299string(1) "
300"
301
302-- file opened in w+t --
303int(1)
304int(1)
305bool(false)
306string(%d) "
307"
308
309-- file opened in x+ --
310int(1)
311int(1)
312bool(false)
313string(1) "
314"
315
316-- file opened in x+b --
317int(1)
318int(1)
319bool(false)
320string(1) "
321"
322
323-- file opened in x+t --
324int(1)
325int(1)
326bool(false)
327string(%d) "
328"
329Done
330