1--TEST--
2Test fputcsv() : usage variations - with default arguments value
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/* Testing fputcsv() to write to a file when default arguments values are considered */
11
12echo "*** Testing fputcsv() : with default arguments value ***\n";
13
14/* the array is with three elements in it. Each element should be read as
15   1st element is delimiter, 2nd element is enclosure
16   and 3rd element is csv fields
17*/
18$csv_lists = array (
19  array(',', '"', array('water','fruit') ),
20  array(',', '"', array('"water","fruit') ),
21  array(',', '"', array('"water","fruit"') ),
22  array(' ', '^', array('^water^ ^fruit^')),
23  array(':', '&', array('&water&:&fruit&')),
24  array('=', '=', array('=water===fruit=')),
25  array('-', '-', array('-water--fruit-air')),
26  array('-', '-', array('-water---fruit---air-')),
27  array(':', '&', array('&""""&:&"&:,:":&,&:,,,,'))
28
29);
30$file_path = dirname(__FILE__);
31$filename = "$file_path/fputcsv_variation5.tmp";
32
33$file_modes = array ("r+", "r+b", "r+t",
34                     "a+", "a+b", "a+t",
35                     "w+", "w+b", "w+t",
36                     "x+", "x+b", "x+t");
37
38$loop_counter = 1;
39foreach ($csv_lists as $csv_list) {
40  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
41
42    echo "\n-- file opened in $file_modes[$mode_counter] --\n";
43    // create the file and add the content with has csv fields
44    if ( strstr($file_modes[$mode_counter], "r") ) {
45      $file_handle = fopen($filename, "w");
46    } else {
47      $file_handle = fopen($filename, $file_modes[$mode_counter] );
48    }
49    if ( !$file_handle ) {
50      echo "Error: failed to create file $filename!\n";
51      exit();
52    }
53    $delimiter = $csv_list[0];
54    $enclosure = $csv_list[1];
55    $csv_field = $csv_list[2];
56
57    // write to a file in csv format
58    var_dump( fputcsv($file_handle, $csv_field) );
59    // check the file pointer position and eof
60    var_dump( ftell($file_handle) );
61    var_dump( feof($file_handle) );
62    //close the file
63    fclose($file_handle);
64
65    // print the file contents
66    var_dump( file_get_contents($filename) );
67
68    //delete file
69    unlink($filename);
70  } //end of mode loop
71} // end of foreach
72
73echo "Done\n";
74?>
75--EXPECTF--
76*** Testing fputcsv() : with default arguments value ***
77
78-- file opened in r+ --
79int(12)
80int(12)
81bool(false)
82string(12) "water,fruit
83"
84
85-- file opened in r+b --
86int(12)
87int(12)
88bool(false)
89string(12) "water,fruit
90"
91
92-- file opened in r+t --
93int(12)
94int(12)
95bool(false)
96string(%d) "water,fruit
97"
98
99-- file opened in a+ --
100int(12)
101int(12)
102bool(false)
103string(12) "water,fruit
104"
105
106-- file opened in a+b --
107int(12)
108int(12)
109bool(false)
110string(12) "water,fruit
111"
112
113-- file opened in a+t --
114int(12)
115int(12)
116bool(false)
117string(%d) "water,fruit
118"
119
120-- file opened in w+ --
121int(12)
122int(12)
123bool(false)
124string(12) "water,fruit
125"
126
127-- file opened in w+b --
128int(12)
129int(12)
130bool(false)
131string(12) "water,fruit
132"
133
134-- file opened in w+t --
135int(12)
136int(12)
137bool(false)
138string(%d) "water,fruit
139"
140
141-- file opened in x+ --
142int(12)
143int(12)
144bool(false)
145string(12) "water,fruit
146"
147
148-- file opened in x+b --
149int(12)
150int(12)
151bool(false)
152string(12) "water,fruit
153"
154
155-- file opened in x+t --
156int(12)
157int(12)
158bool(false)
159string(%d) "water,fruit
160"
161
162-- file opened in r+ --
163int(20)
164int(20)
165bool(false)
166string(20) """"water"",""fruit"
167"
168
169-- file opened in r+b --
170int(20)
171int(20)
172bool(false)
173string(20) """"water"",""fruit"
174"
175
176-- file opened in r+t --
177int(20)
178int(20)
179bool(false)
180string(%d) """"water"",""fruit"
181"
182
183-- file opened in a+ --
184int(20)
185int(20)
186bool(false)
187string(20) """"water"",""fruit"
188"
189
190-- file opened in a+b --
191int(20)
192int(20)
193bool(false)
194string(20) """"water"",""fruit"
195"
196
197-- file opened in a+t --
198int(20)
199int(20)
200bool(false)
201string(%d) """"water"",""fruit"
202"
203
204-- file opened in w+ --
205int(20)
206int(20)
207bool(false)
208string(20) """"water"",""fruit"
209"
210
211-- file opened in w+b --
212int(20)
213int(20)
214bool(false)
215string(20) """"water"",""fruit"
216"
217
218-- file opened in w+t --
219int(20)
220int(20)
221bool(false)
222string(%d) """"water"",""fruit"
223"
224
225-- file opened in x+ --
226int(20)
227int(20)
228bool(false)
229string(20) """"water"",""fruit"
230"
231
232-- file opened in x+b --
233int(20)
234int(20)
235bool(false)
236string(20) """"water"",""fruit"
237"
238
239-- file opened in x+t --
240int(20)
241int(20)
242bool(false)
243string(%d) """"water"",""fruit"
244"
245
246-- file opened in r+ --
247int(22)
248int(22)
249bool(false)
250string(22) """"water"",""fruit"""
251"
252
253-- file opened in r+b --
254int(22)
255int(22)
256bool(false)
257string(22) """"water"",""fruit"""
258"
259
260-- file opened in r+t --
261int(22)
262int(22)
263bool(false)
264string(%d) """"water"",""fruit"""
265"
266
267-- file opened in a+ --
268int(22)
269int(22)
270bool(false)
271string(22) """"water"",""fruit"""
272"
273
274-- file opened in a+b --
275int(22)
276int(22)
277bool(false)
278string(22) """"water"",""fruit"""
279"
280
281-- file opened in a+t --
282int(22)
283int(22)
284bool(false)
285string(%d) """"water"",""fruit"""
286"
287
288-- file opened in w+ --
289int(22)
290int(22)
291bool(false)
292string(22) """"water"",""fruit"""
293"
294
295-- file opened in w+b --
296int(22)
297int(22)
298bool(false)
299string(22) """"water"",""fruit"""
300"
301
302-- file opened in w+t --
303int(22)
304int(22)
305bool(false)
306string(%d) """"water"",""fruit"""
307"
308
309-- file opened in x+ --
310int(22)
311int(22)
312bool(false)
313string(22) """"water"",""fruit"""
314"
315
316-- file opened in x+b --
317int(22)
318int(22)
319bool(false)
320string(22) """"water"",""fruit"""
321"
322
323-- file opened in x+t --
324int(22)
325int(22)
326bool(false)
327string(%d) """"water"",""fruit"""
328"
329
330-- file opened in r+ --
331int(18)
332int(18)
333bool(false)
334string(18) ""^water^ ^fruit^"
335"
336
337-- file opened in r+b --
338int(18)
339int(18)
340bool(false)
341string(18) ""^water^ ^fruit^"
342"
343
344-- file opened in r+t --
345int(18)
346int(18)
347bool(false)
348string(%d) ""^water^ ^fruit^"
349"
350
351-- file opened in a+ --
352int(18)
353int(18)
354bool(false)
355string(18) ""^water^ ^fruit^"
356"
357
358-- file opened in a+b --
359int(18)
360int(18)
361bool(false)
362string(18) ""^water^ ^fruit^"
363"
364
365-- file opened in a+t --
366int(18)
367int(18)
368bool(false)
369string(%d) ""^water^ ^fruit^"
370"
371
372-- file opened in w+ --
373int(18)
374int(18)
375bool(false)
376string(18) ""^water^ ^fruit^"
377"
378
379-- file opened in w+b --
380int(18)
381int(18)
382bool(false)
383string(18) ""^water^ ^fruit^"
384"
385
386-- file opened in w+t --
387int(18)
388int(18)
389bool(false)
390string(%d) ""^water^ ^fruit^"
391"
392
393-- file opened in x+ --
394int(18)
395int(18)
396bool(false)
397string(18) ""^water^ ^fruit^"
398"
399
400-- file opened in x+b --
401int(18)
402int(18)
403bool(false)
404string(18) ""^water^ ^fruit^"
405"
406
407-- file opened in x+t --
408int(18)
409int(18)
410bool(false)
411string(%d) ""^water^ ^fruit^"
412"
413
414-- file opened in r+ --
415int(16)
416int(16)
417bool(false)
418string(16) "&water&:&fruit&
419"
420
421-- file opened in r+b --
422int(16)
423int(16)
424bool(false)
425string(16) "&water&:&fruit&
426"
427
428-- file opened in r+t --
429int(16)
430int(16)
431bool(false)
432string(%d) "&water&:&fruit&
433"
434
435-- file opened in a+ --
436int(16)
437int(16)
438bool(false)
439string(16) "&water&:&fruit&
440"
441
442-- file opened in a+b --
443int(16)
444int(16)
445bool(false)
446string(16) "&water&:&fruit&
447"
448
449-- file opened in a+t --
450int(16)
451int(16)
452bool(false)
453string(%d) "&water&:&fruit&
454"
455
456-- file opened in w+ --
457int(16)
458int(16)
459bool(false)
460string(16) "&water&:&fruit&
461"
462
463-- file opened in w+b --
464int(16)
465int(16)
466bool(false)
467string(16) "&water&:&fruit&
468"
469
470-- file opened in w+t --
471int(16)
472int(16)
473bool(false)
474string(%d) "&water&:&fruit&
475"
476
477-- file opened in x+ --
478int(16)
479int(16)
480bool(false)
481string(16) "&water&:&fruit&
482"
483
484-- file opened in x+b --
485int(16)
486int(16)
487bool(false)
488string(16) "&water&:&fruit&
489"
490
491-- file opened in x+t --
492int(16)
493int(16)
494bool(false)
495string(%d) "&water&:&fruit&
496"
497
498-- file opened in r+ --
499int(16)
500int(16)
501bool(false)
502string(16) "=water===fruit=
503"
504
505-- file opened in r+b --
506int(16)
507int(16)
508bool(false)
509string(16) "=water===fruit=
510"
511
512-- file opened in r+t --
513int(16)
514int(16)
515bool(false)
516string(%d) "=water===fruit=
517"
518
519-- file opened in a+ --
520int(16)
521int(16)
522bool(false)
523string(16) "=water===fruit=
524"
525
526-- file opened in a+b --
527int(16)
528int(16)
529bool(false)
530string(16) "=water===fruit=
531"
532
533-- file opened in a+t --
534int(16)
535int(16)
536bool(false)
537string(%d) "=water===fruit=
538"
539
540-- file opened in w+ --
541int(16)
542int(16)
543bool(false)
544string(16) "=water===fruit=
545"
546
547-- file opened in w+b --
548int(16)
549int(16)
550bool(false)
551string(16) "=water===fruit=
552"
553
554-- file opened in w+t --
555int(16)
556int(16)
557bool(false)
558string(%d) "=water===fruit=
559"
560
561-- file opened in x+ --
562int(16)
563int(16)
564bool(false)
565string(16) "=water===fruit=
566"
567
568-- file opened in x+b --
569int(16)
570int(16)
571bool(false)
572string(16) "=water===fruit=
573"
574
575-- file opened in x+t --
576int(16)
577int(16)
578bool(false)
579string(%d) "=water===fruit=
580"
581
582-- file opened in r+ --
583int(18)
584int(18)
585bool(false)
586string(18) "-water--fruit-air
587"
588
589-- file opened in r+b --
590int(18)
591int(18)
592bool(false)
593string(18) "-water--fruit-air
594"
595
596-- file opened in r+t --
597int(18)
598int(18)
599bool(false)
600string(%d) "-water--fruit-air
601"
602
603-- file opened in a+ --
604int(18)
605int(18)
606bool(false)
607string(18) "-water--fruit-air
608"
609
610-- file opened in a+b --
611int(18)
612int(18)
613bool(false)
614string(18) "-water--fruit-air
615"
616
617-- file opened in a+t --
618int(18)
619int(18)
620bool(false)
621string(%d) "-water--fruit-air
622"
623
624-- file opened in w+ --
625int(18)
626int(18)
627bool(false)
628string(18) "-water--fruit-air
629"
630
631-- file opened in w+b --
632int(18)
633int(18)
634bool(false)
635string(18) "-water--fruit-air
636"
637
638-- file opened in w+t --
639int(18)
640int(18)
641bool(false)
642string(%d) "-water--fruit-air
643"
644
645-- file opened in x+ --
646int(18)
647int(18)
648bool(false)
649string(18) "-water--fruit-air
650"
651
652-- file opened in x+b --
653int(18)
654int(18)
655bool(false)
656string(18) "-water--fruit-air
657"
658
659-- file opened in x+t --
660int(18)
661int(18)
662bool(false)
663string(%d) "-water--fruit-air
664"
665
666-- file opened in r+ --
667int(22)
668int(22)
669bool(false)
670string(22) "-water---fruit---air-
671"
672
673-- file opened in r+b --
674int(22)
675int(22)
676bool(false)
677string(22) "-water---fruit---air-
678"
679
680-- file opened in r+t --
681int(22)
682int(22)
683bool(false)
684string(%d) "-water---fruit---air-
685"
686
687-- file opened in a+ --
688int(22)
689int(22)
690bool(false)
691string(22) "-water---fruit---air-
692"
693
694-- file opened in a+b --
695int(22)
696int(22)
697bool(false)
698string(22) "-water---fruit---air-
699"
700
701-- file opened in a+t --
702int(22)
703int(22)
704bool(false)
705string(%d) "-water---fruit---air-
706"
707
708-- file opened in w+ --
709int(22)
710int(22)
711bool(false)
712string(22) "-water---fruit---air-
713"
714
715-- file opened in w+b --
716int(22)
717int(22)
718bool(false)
719string(22) "-water---fruit---air-
720"
721
722-- file opened in w+t --
723int(22)
724int(22)
725bool(false)
726string(%d) "-water---fruit---air-
727"
728
729-- file opened in x+ --
730int(22)
731int(22)
732bool(false)
733string(22) "-water---fruit---air-
734"
735
736-- file opened in x+b --
737int(22)
738int(22)
739bool(false)
740string(22) "-water---fruit---air-
741"
742
743-- file opened in x+t --
744int(22)
745int(22)
746bool(false)
747string(%d) "-water---fruit---air-
748"
749
750-- file opened in r+ --
751int(32)
752int(32)
753bool(false)
754string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
755"
756
757-- file opened in r+b --
758int(32)
759int(32)
760bool(false)
761string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
762"
763
764-- file opened in r+t --
765int(32)
766int(32)
767bool(false)
768string(%d) ""&""""""""&:&""&:,:"":&,&:,,,,"
769"
770
771-- file opened in a+ --
772int(32)
773int(32)
774bool(false)
775string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
776"
777
778-- file opened in a+b --
779int(32)
780int(32)
781bool(false)
782string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
783"
784
785-- file opened in a+t --
786int(32)
787int(32)
788bool(false)
789string(%d) ""&""""""""&:&""&:,:"":&,&:,,,,"
790"
791
792-- file opened in w+ --
793int(32)
794int(32)
795bool(false)
796string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
797"
798
799-- file opened in w+b --
800int(32)
801int(32)
802bool(false)
803string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
804"
805
806-- file opened in w+t --
807int(32)
808int(32)
809bool(false)
810string(%d) ""&""""""""&:&""&:,:"":&,&:,,,,"
811"
812
813-- file opened in x+ --
814int(32)
815int(32)
816bool(false)
817string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
818"
819
820-- file opened in x+b --
821int(32)
822int(32)
823bool(false)
824string(32) ""&""""""""&:&""&:,:"":&,&:,,,,"
825"
826
827-- file opened in x+t --
828int(32)
829int(32)
830bool(false)
831string(%d) ""&""""""""&:&""&:,:"":&,&:,,,,"
832"
833Done
834
835