1--TEST--
2SplFileObject::fputcsv(): Usage variations -- with default enclosure value
3--FILE--
4<?php
5
6/* Testing fputcsv() to write to a file when default enclosure value is provided */
7
8echo "*** Testing fputcsv() : with default enclosure value ***\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_variation11.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    // write to a file in csv format
50    var_dump( $fo->fputcsv($csv_field, $delimiter) );
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 default enclosure value ***
69
70-- file opened in r+ --
71int(14)
72int(14)
73bool(false)
74string(14) ""water,fruit"
75"
76
77-- file opened in r+b --
78int(14)
79int(14)
80bool(false)
81string(14) ""water,fruit"
82"
83
84-- file opened in r+t --
85int(14)
86int(14)
87bool(false)
88string(%d) ""water,fruit"
89"
90
91-- file opened in a+ --
92int(14)
93int(14)
94bool(false)
95string(14) ""water,fruit"
96"
97
98-- file opened in a+b --
99int(14)
100int(14)
101bool(false)
102string(14) ""water,fruit"
103"
104
105-- file opened in a+t --
106int(14)
107int(14)
108bool(false)
109string(%d) ""water,fruit"
110"
111
112-- file opened in w+ --
113int(14)
114int(14)
115bool(false)
116string(14) ""water,fruit"
117"
118
119-- file opened in w+b --
120int(14)
121int(14)
122bool(false)
123string(14) ""water,fruit"
124"
125
126-- file opened in w+t --
127int(14)
128int(14)
129bool(false)
130string(%d) ""water,fruit"
131"
132
133-- file opened in x+ --
134int(14)
135int(14)
136bool(false)
137string(14) ""water,fruit"
138"
139
140-- file opened in x+b --
141int(14)
142int(14)
143bool(false)
144string(14) ""water,fruit"
145"
146
147-- file opened in x+t --
148int(14)
149int(14)
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(18)
324int(18)
325bool(false)
326string(18) ""^water^ ^fruit^"
327"
328
329-- file opened in r+b --
330int(18)
331int(18)
332bool(false)
333string(18) ""^water^ ^fruit^"
334"
335
336-- file opened in r+t --
337int(18)
338int(18)
339bool(false)
340string(%d) ""^water^ ^fruit^"
341"
342
343-- file opened in a+ --
344int(18)
345int(18)
346bool(false)
347string(18) ""^water^ ^fruit^"
348"
349
350-- file opened in a+b --
351int(18)
352int(18)
353bool(false)
354string(18) ""^water^ ^fruit^"
355"
356
357-- file opened in a+t --
358int(18)
359int(18)
360bool(false)
361string(%d) ""^water^ ^fruit^"
362"
363
364-- file opened in w+ --
365int(18)
366int(18)
367bool(false)
368string(18) ""^water^ ^fruit^"
369"
370
371-- file opened in w+b --
372int(18)
373int(18)
374bool(false)
375string(18) ""^water^ ^fruit^"
376"
377
378-- file opened in w+t --
379int(18)
380int(18)
381bool(false)
382string(%d) ""^water^ ^fruit^"
383"
384
385-- file opened in x+ --
386int(18)
387int(18)
388bool(false)
389string(18) ""^water^ ^fruit^"
390"
391
392-- file opened in x+b --
393int(18)
394int(18)
395bool(false)
396string(18) ""^water^ ^fruit^"
397"
398
399-- file opened in x+t --
400int(18)
401int(18)
402bool(false)
403string(%d) ""^water^ ^fruit^"
404"
405
406-- file opened in r+ --
407int(18)
408int(18)
409bool(false)
410string(18) ""&water&:&fruit&"
411"
412
413-- file opened in r+b --
414int(18)
415int(18)
416bool(false)
417string(18) ""&water&:&fruit&"
418"
419
420-- file opened in r+t --
421int(18)
422int(18)
423bool(false)
424string(%d) ""&water&:&fruit&"
425"
426
427-- file opened in a+ --
428int(18)
429int(18)
430bool(false)
431string(18) ""&water&:&fruit&"
432"
433
434-- file opened in a+b --
435int(18)
436int(18)
437bool(false)
438string(18) ""&water&:&fruit&"
439"
440
441-- file opened in a+t --
442int(18)
443int(18)
444bool(false)
445string(%d) ""&water&:&fruit&"
446"
447
448-- file opened in w+ --
449int(18)
450int(18)
451bool(false)
452string(18) ""&water&:&fruit&"
453"
454
455-- file opened in w+b --
456int(18)
457int(18)
458bool(false)
459string(18) ""&water&:&fruit&"
460"
461
462-- file opened in w+t --
463int(18)
464int(18)
465bool(false)
466string(%d) ""&water&:&fruit&"
467"
468
469-- file opened in x+ --
470int(18)
471int(18)
472bool(false)
473string(18) ""&water&:&fruit&"
474"
475
476-- file opened in x+b --
477int(18)
478int(18)
479bool(false)
480string(18) ""&water&:&fruit&"
481"
482
483-- file opened in x+t --
484int(18)
485int(18)
486bool(false)
487string(%d) ""&water&:&fruit&"
488"
489
490-- file opened in r+ --
491int(18)
492int(18)
493bool(false)
494string(18) ""=water===fruit="
495"
496
497-- file opened in r+b --
498int(18)
499int(18)
500bool(false)
501string(18) ""=water===fruit="
502"
503
504-- file opened in r+t --
505int(18)
506int(18)
507bool(false)
508string(%d) ""=water===fruit="
509"
510
511-- file opened in a+ --
512int(18)
513int(18)
514bool(false)
515string(18) ""=water===fruit="
516"
517
518-- file opened in a+b --
519int(18)
520int(18)
521bool(false)
522string(18) ""=water===fruit="
523"
524
525-- file opened in a+t --
526int(18)
527int(18)
528bool(false)
529string(%d) ""=water===fruit="
530"
531
532-- file opened in w+ --
533int(18)
534int(18)
535bool(false)
536string(18) ""=water===fruit="
537"
538
539-- file opened in w+b --
540int(18)
541int(18)
542bool(false)
543string(18) ""=water===fruit="
544"
545
546-- file opened in w+t --
547int(18)
548int(18)
549bool(false)
550string(%d) ""=water===fruit="
551"
552
553-- file opened in x+ --
554int(18)
555int(18)
556bool(false)
557string(18) ""=water===fruit="
558"
559
560-- file opened in x+b --
561int(18)
562int(18)
563bool(false)
564string(18) ""=water===fruit="
565"
566
567-- file opened in x+t --
568int(18)
569int(18)
570bool(false)
571string(%d) ""=water===fruit="
572"
573
574-- file opened in r+ --
575int(20)
576int(20)
577bool(false)
578string(20) ""-water--fruit-air"
579"
580
581-- file opened in r+b --
582int(20)
583int(20)
584bool(false)
585string(20) ""-water--fruit-air"
586"
587
588-- file opened in r+t --
589int(20)
590int(20)
591bool(false)
592string(%d) ""-water--fruit-air"
593"
594
595-- file opened in a+ --
596int(20)
597int(20)
598bool(false)
599string(20) ""-water--fruit-air"
600"
601
602-- file opened in a+b --
603int(20)
604int(20)
605bool(false)
606string(20) ""-water--fruit-air"
607"
608
609-- file opened in a+t --
610int(20)
611int(20)
612bool(false)
613string(%d) ""-water--fruit-air"
614"
615
616-- file opened in w+ --
617int(20)
618int(20)
619bool(false)
620string(20) ""-water--fruit-air"
621"
622
623-- file opened in w+b --
624int(20)
625int(20)
626bool(false)
627string(20) ""-water--fruit-air"
628"
629
630-- file opened in w+t --
631int(20)
632int(20)
633bool(false)
634string(%d) ""-water--fruit-air"
635"
636
637-- file opened in x+ --
638int(20)
639int(20)
640bool(false)
641string(20) ""-water--fruit-air"
642"
643
644-- file opened in x+b --
645int(20)
646int(20)
647bool(false)
648string(20) ""-water--fruit-air"
649"
650
651-- file opened in x+t --
652int(20)
653int(20)
654bool(false)
655string(%d) ""-water--fruit-air"
656"
657
658-- file opened in r+ --
659int(24)
660int(24)
661bool(false)
662string(24) ""-water---fruit---air-"
663"
664
665-- file opened in r+b --
666int(24)
667int(24)
668bool(false)
669string(24) ""-water---fruit---air-"
670"
671
672-- file opened in r+t --
673int(24)
674int(24)
675bool(false)
676string(%d) ""-water---fruit---air-"
677"
678
679-- file opened in a+ --
680int(24)
681int(24)
682bool(false)
683string(24) ""-water---fruit---air-"
684"
685
686-- file opened in a+b --
687int(24)
688int(24)
689bool(false)
690string(24) ""-water---fruit---air-"
691"
692
693-- file opened in a+t --
694int(24)
695int(24)
696bool(false)
697string(%d) ""-water---fruit---air-"
698"
699
700-- file opened in w+ --
701int(24)
702int(24)
703bool(false)
704string(24) ""-water---fruit---air-"
705"
706
707-- file opened in w+b --
708int(24)
709int(24)
710bool(false)
711string(24) ""-water---fruit---air-"
712"
713
714-- file opened in w+t --
715int(24)
716int(24)
717bool(false)
718string(%d) ""-water---fruit---air-"
719"
720
721-- file opened in x+ --
722int(24)
723int(24)
724bool(false)
725string(24) ""-water---fruit---air-"
726"
727
728-- file opened in x+b --
729int(24)
730int(24)
731bool(false)
732string(24) ""-water---fruit---air-"
733"
734
735-- file opened in x+t --
736int(24)
737int(24)
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