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