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