1--TEST--
2Test fputcsv() : usage variations - with delimiter as NULL
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 delimiter is NULL */
11
12echo "*** Testing fputcsv() : with delimiter as NULL ***\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_variation2.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, NULL, $enclosure) );
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 delimiter as NULL ***
77
78-- file opened in r+ --
79
80Warning: fputcsv(): delimiter must be a character in %s on line %d
81bool(false)
82int(0)
83bool(false)
84string(0) ""
85
86-- file opened in r+b --
87
88Warning: fputcsv(): delimiter must be a character in %s on line %d
89bool(false)
90int(0)
91bool(false)
92string(0) ""
93
94-- file opened in r+t --
95
96Warning: fputcsv(): delimiter must be a character in %s on line %d
97bool(false)
98int(0)
99bool(false)
100string(0) ""
101
102-- file opened in a+ --
103
104Warning: fputcsv(): delimiter must be a character in %s on line %d
105bool(false)
106int(0)
107bool(false)
108string(0) ""
109
110-- file opened in a+b --
111
112Warning: fputcsv(): delimiter must be a character in %s on line %d
113bool(false)
114int(0)
115bool(false)
116string(0) ""
117
118-- file opened in a+t --
119
120Warning: fputcsv(): delimiter must be a character in %s on line %d
121bool(false)
122int(0)
123bool(false)
124string(0) ""
125
126-- file opened in w+ --
127
128Warning: fputcsv(): delimiter must be a character in %s on line %d
129bool(false)
130int(0)
131bool(false)
132string(0) ""
133
134-- file opened in w+b --
135
136Warning: fputcsv(): delimiter must be a character in %s on line %d
137bool(false)
138int(0)
139bool(false)
140string(0) ""
141
142-- file opened in w+t --
143
144Warning: fputcsv(): delimiter must be a character in %s on line %d
145bool(false)
146int(0)
147bool(false)
148string(0) ""
149
150-- file opened in x+ --
151
152Warning: fputcsv(): delimiter must be a character in %s on line %d
153bool(false)
154int(0)
155bool(false)
156string(0) ""
157
158-- file opened in x+b --
159
160Warning: fputcsv(): delimiter must be a character in %s on line %d
161bool(false)
162int(0)
163bool(false)
164string(0) ""
165
166-- file opened in x+t --
167
168Warning: fputcsv(): delimiter must be a character in %s on line %d
169bool(false)
170int(0)
171bool(false)
172string(0) ""
173
174-- file opened in r+ --
175
176Warning: fputcsv(): delimiter must be a character in %s on line %d
177bool(false)
178int(0)
179bool(false)
180string(0) ""
181
182-- file opened in r+b --
183
184Warning: fputcsv(): delimiter must be a character in %s on line %d
185bool(false)
186int(0)
187bool(false)
188string(0) ""
189
190-- file opened in r+t --
191
192Warning: fputcsv(): delimiter must be a character in %s on line %d
193bool(false)
194int(0)
195bool(false)
196string(0) ""
197
198-- file opened in a+ --
199
200Warning: fputcsv(): delimiter must be a character in %s on line %d
201bool(false)
202int(0)
203bool(false)
204string(0) ""
205
206-- file opened in a+b --
207
208Warning: fputcsv(): delimiter must be a character in %s on line %d
209bool(false)
210int(0)
211bool(false)
212string(0) ""
213
214-- file opened in a+t --
215
216Warning: fputcsv(): delimiter must be a character in %s on line %d
217bool(false)
218int(0)
219bool(false)
220string(0) ""
221
222-- file opened in w+ --
223
224Warning: fputcsv(): delimiter must be a character in %s on line %d
225bool(false)
226int(0)
227bool(false)
228string(0) ""
229
230-- file opened in w+b --
231
232Warning: fputcsv(): delimiter must be a character in %s on line %d
233bool(false)
234int(0)
235bool(false)
236string(0) ""
237
238-- file opened in w+t --
239
240Warning: fputcsv(): delimiter must be a character in %s on line %d
241bool(false)
242int(0)
243bool(false)
244string(0) ""
245
246-- file opened in x+ --
247
248Warning: fputcsv(): delimiter must be a character in %s on line %d
249bool(false)
250int(0)
251bool(false)
252string(0) ""
253
254-- file opened in x+b --
255
256Warning: fputcsv(): delimiter must be a character in %s on line %d
257bool(false)
258int(0)
259bool(false)
260string(0) ""
261
262-- file opened in x+t --
263
264Warning: fputcsv(): delimiter must be a character in %s on line %d
265bool(false)
266int(0)
267bool(false)
268string(0) ""
269
270-- file opened in r+ --
271
272Warning: fputcsv(): delimiter must be a character in %s on line %d
273bool(false)
274int(0)
275bool(false)
276string(0) ""
277
278-- file opened in r+b --
279
280Warning: fputcsv(): delimiter must be a character in %s on line %d
281bool(false)
282int(0)
283bool(false)
284string(0) ""
285
286-- file opened in r+t --
287
288Warning: fputcsv(): delimiter must be a character in %s on line %d
289bool(false)
290int(0)
291bool(false)
292string(0) ""
293
294-- file opened in a+ --
295
296Warning: fputcsv(): delimiter must be a character in %s on line %d
297bool(false)
298int(0)
299bool(false)
300string(0) ""
301
302-- file opened in a+b --
303
304Warning: fputcsv(): delimiter must be a character in %s on line %d
305bool(false)
306int(0)
307bool(false)
308string(0) ""
309
310-- file opened in a+t --
311
312Warning: fputcsv(): delimiter must be a character in %s on line %d
313bool(false)
314int(0)
315bool(false)
316string(0) ""
317
318-- file opened in w+ --
319
320Warning: fputcsv(): delimiter must be a character in %s on line %d
321bool(false)
322int(0)
323bool(false)
324string(0) ""
325
326-- file opened in w+b --
327
328Warning: fputcsv(): delimiter must be a character in %s on line %d
329bool(false)
330int(0)
331bool(false)
332string(0) ""
333
334-- file opened in w+t --
335
336Warning: fputcsv(): delimiter must be a character in %s on line %d
337bool(false)
338int(0)
339bool(false)
340string(0) ""
341
342-- file opened in x+ --
343
344Warning: fputcsv(): delimiter must be a character in %s on line %d
345bool(false)
346int(0)
347bool(false)
348string(0) ""
349
350-- file opened in x+b --
351
352Warning: fputcsv(): delimiter must be a character in %s on line %d
353bool(false)
354int(0)
355bool(false)
356string(0) ""
357
358-- file opened in x+t --
359
360Warning: fputcsv(): delimiter must be a character in %s on line %d
361bool(false)
362int(0)
363bool(false)
364string(0) ""
365
366-- file opened in r+ --
367
368Warning: fputcsv(): delimiter must be a character in %s on line %d
369bool(false)
370int(0)
371bool(false)
372string(0) ""
373
374-- file opened in r+b --
375
376Warning: fputcsv(): delimiter must be a character in %s on line %d
377bool(false)
378int(0)
379bool(false)
380string(0) ""
381
382-- file opened in r+t --
383
384Warning: fputcsv(): delimiter must be a character in %s on line %d
385bool(false)
386int(0)
387bool(false)
388string(0) ""
389
390-- file opened in a+ --
391
392Warning: fputcsv(): delimiter must be a character in %s on line %d
393bool(false)
394int(0)
395bool(false)
396string(0) ""
397
398-- file opened in a+b --
399
400Warning: fputcsv(): delimiter must be a character in %s on line %d
401bool(false)
402int(0)
403bool(false)
404string(0) ""
405
406-- file opened in a+t --
407
408Warning: fputcsv(): delimiter must be a character in %s on line %d
409bool(false)
410int(0)
411bool(false)
412string(0) ""
413
414-- file opened in w+ --
415
416Warning: fputcsv(): delimiter must be a character in %s on line %d
417bool(false)
418int(0)
419bool(false)
420string(0) ""
421
422-- file opened in w+b --
423
424Warning: fputcsv(): delimiter must be a character in %s on line %d
425bool(false)
426int(0)
427bool(false)
428string(0) ""
429
430-- file opened in w+t --
431
432Warning: fputcsv(): delimiter must be a character in %s on line %d
433bool(false)
434int(0)
435bool(false)
436string(0) ""
437
438-- file opened in x+ --
439
440Warning: fputcsv(): delimiter must be a character in %s on line %d
441bool(false)
442int(0)
443bool(false)
444string(0) ""
445
446-- file opened in x+b --
447
448Warning: fputcsv(): delimiter must be a character in %s on line %d
449bool(false)
450int(0)
451bool(false)
452string(0) ""
453
454-- file opened in x+t --
455
456Warning: fputcsv(): delimiter must be a character in %s on line %d
457bool(false)
458int(0)
459bool(false)
460string(0) ""
461
462-- file opened in r+ --
463
464Warning: fputcsv(): delimiter must be a character in %s on line %d
465bool(false)
466int(0)
467bool(false)
468string(0) ""
469
470-- file opened in r+b --
471
472Warning: fputcsv(): delimiter must be a character in %s on line %d
473bool(false)
474int(0)
475bool(false)
476string(0) ""
477
478-- file opened in r+t --
479
480Warning: fputcsv(): delimiter must be a character in %s on line %d
481bool(false)
482int(0)
483bool(false)
484string(0) ""
485
486-- file opened in a+ --
487
488Warning: fputcsv(): delimiter must be a character in %s on line %d
489bool(false)
490int(0)
491bool(false)
492string(0) ""
493
494-- file opened in a+b --
495
496Warning: fputcsv(): delimiter must be a character in %s on line %d
497bool(false)
498int(0)
499bool(false)
500string(0) ""
501
502-- file opened in a+t --
503
504Warning: fputcsv(): delimiter must be a character in %s on line %d
505bool(false)
506int(0)
507bool(false)
508string(0) ""
509
510-- file opened in w+ --
511
512Warning: fputcsv(): delimiter must be a character in %s on line %d
513bool(false)
514int(0)
515bool(false)
516string(0) ""
517
518-- file opened in w+b --
519
520Warning: fputcsv(): delimiter must be a character in %s on line %d
521bool(false)
522int(0)
523bool(false)
524string(0) ""
525
526-- file opened in w+t --
527
528Warning: fputcsv(): delimiter must be a character in %s on line %d
529bool(false)
530int(0)
531bool(false)
532string(0) ""
533
534-- file opened in x+ --
535
536Warning: fputcsv(): delimiter must be a character in %s on line %d
537bool(false)
538int(0)
539bool(false)
540string(0) ""
541
542-- file opened in x+b --
543
544Warning: fputcsv(): delimiter must be a character in %s on line %d
545bool(false)
546int(0)
547bool(false)
548string(0) ""
549
550-- file opened in x+t --
551
552Warning: fputcsv(): delimiter must be a character in %s on line %d
553bool(false)
554int(0)
555bool(false)
556string(0) ""
557
558-- file opened in r+ --
559
560Warning: fputcsv(): delimiter must be a character in %s on line %d
561bool(false)
562int(0)
563bool(false)
564string(0) ""
565
566-- file opened in r+b --
567
568Warning: fputcsv(): delimiter must be a character in %s on line %d
569bool(false)
570int(0)
571bool(false)
572string(0) ""
573
574-- file opened in r+t --
575
576Warning: fputcsv(): delimiter must be a character in %s on line %d
577bool(false)
578int(0)
579bool(false)
580string(0) ""
581
582-- file opened in a+ --
583
584Warning: fputcsv(): delimiter must be a character in %s on line %d
585bool(false)
586int(0)
587bool(false)
588string(0) ""
589
590-- file opened in a+b --
591
592Warning: fputcsv(): delimiter must be a character in %s on line %d
593bool(false)
594int(0)
595bool(false)
596string(0) ""
597
598-- file opened in a+t --
599
600Warning: fputcsv(): delimiter must be a character in %s on line %d
601bool(false)
602int(0)
603bool(false)
604string(0) ""
605
606-- file opened in w+ --
607
608Warning: fputcsv(): delimiter must be a character in %s on line %d
609bool(false)
610int(0)
611bool(false)
612string(0) ""
613
614-- file opened in w+b --
615
616Warning: fputcsv(): delimiter must be a character in %s on line %d
617bool(false)
618int(0)
619bool(false)
620string(0) ""
621
622-- file opened in w+t --
623
624Warning: fputcsv(): delimiter must be a character in %s on line %d
625bool(false)
626int(0)
627bool(false)
628string(0) ""
629
630-- file opened in x+ --
631
632Warning: fputcsv(): delimiter must be a character in %s on line %d
633bool(false)
634int(0)
635bool(false)
636string(0) ""
637
638-- file opened in x+b --
639
640Warning: fputcsv(): delimiter must be a character in %s on line %d
641bool(false)
642int(0)
643bool(false)
644string(0) ""
645
646-- file opened in x+t --
647
648Warning: fputcsv(): delimiter must be a character in %s on line %d
649bool(false)
650int(0)
651bool(false)
652string(0) ""
653
654-- file opened in r+ --
655
656Warning: fputcsv(): delimiter must be a character in %s on line %d
657bool(false)
658int(0)
659bool(false)
660string(0) ""
661
662-- file opened in r+b --
663
664Warning: fputcsv(): delimiter must be a character in %s on line %d
665bool(false)
666int(0)
667bool(false)
668string(0) ""
669
670-- file opened in r+t --
671
672Warning: fputcsv(): delimiter must be a character in %s on line %d
673bool(false)
674int(0)
675bool(false)
676string(0) ""
677
678-- file opened in a+ --
679
680Warning: fputcsv(): delimiter must be a character in %s on line %d
681bool(false)
682int(0)
683bool(false)
684string(0) ""
685
686-- file opened in a+b --
687
688Warning: fputcsv(): delimiter must be a character in %s on line %d
689bool(false)
690int(0)
691bool(false)
692string(0) ""
693
694-- file opened in a+t --
695
696Warning: fputcsv(): delimiter must be a character in %s on line %d
697bool(false)
698int(0)
699bool(false)
700string(0) ""
701
702-- file opened in w+ --
703
704Warning: fputcsv(): delimiter must be a character in %s on line %d
705bool(false)
706int(0)
707bool(false)
708string(0) ""
709
710-- file opened in w+b --
711
712Warning: fputcsv(): delimiter must be a character in %s on line %d
713bool(false)
714int(0)
715bool(false)
716string(0) ""
717
718-- file opened in w+t --
719
720Warning: fputcsv(): delimiter must be a character in %s on line %d
721bool(false)
722int(0)
723bool(false)
724string(0) ""
725
726-- file opened in x+ --
727
728Warning: fputcsv(): delimiter must be a character in %s on line %d
729bool(false)
730int(0)
731bool(false)
732string(0) ""
733
734-- file opened in x+b --
735
736Warning: fputcsv(): delimiter must be a character in %s on line %d
737bool(false)
738int(0)
739bool(false)
740string(0) ""
741
742-- file opened in x+t --
743
744Warning: fputcsv(): delimiter must be a character in %s on line %d
745bool(false)
746int(0)
747bool(false)
748string(0) ""
749
750-- file opened in r+ --
751
752Warning: fputcsv(): delimiter must be a character in %s on line %d
753bool(false)
754int(0)
755bool(false)
756string(0) ""
757
758-- file opened in r+b --
759
760Warning: fputcsv(): delimiter must be a character in %s on line %d
761bool(false)
762int(0)
763bool(false)
764string(0) ""
765
766-- file opened in r+t --
767
768Warning: fputcsv(): delimiter must be a character in %s on line %d
769bool(false)
770int(0)
771bool(false)
772string(0) ""
773
774-- file opened in a+ --
775
776Warning: fputcsv(): delimiter must be a character in %s on line %d
777bool(false)
778int(0)
779bool(false)
780string(0) ""
781
782-- file opened in a+b --
783
784Warning: fputcsv(): delimiter must be a character in %s on line %d
785bool(false)
786int(0)
787bool(false)
788string(0) ""
789
790-- file opened in a+t --
791
792Warning: fputcsv(): delimiter must be a character in %s on line %d
793bool(false)
794int(0)
795bool(false)
796string(0) ""
797
798-- file opened in w+ --
799
800Warning: fputcsv(): delimiter must be a character in %s on line %d
801bool(false)
802int(0)
803bool(false)
804string(0) ""
805
806-- file opened in w+b --
807
808Warning: fputcsv(): delimiter must be a character in %s on line %d
809bool(false)
810int(0)
811bool(false)
812string(0) ""
813
814-- file opened in w+t --
815
816Warning: fputcsv(): delimiter must be a character in %s on line %d
817bool(false)
818int(0)
819bool(false)
820string(0) ""
821
822-- file opened in x+ --
823
824Warning: fputcsv(): delimiter must be a character in %s on line %d
825bool(false)
826int(0)
827bool(false)
828string(0) ""
829
830-- file opened in x+b --
831
832Warning: fputcsv(): delimiter must be a character in %s on line %d
833bool(false)
834int(0)
835bool(false)
836string(0) ""
837
838-- file opened in x+t --
839
840Warning: fputcsv(): delimiter must be a character in %s on line %d
841bool(false)
842int(0)
843bool(false)
844string(0) ""
845
846-- file opened in r+ --
847
848Warning: fputcsv(): delimiter must be a character in %s on line %d
849bool(false)
850int(0)
851bool(false)
852string(0) ""
853
854-- file opened in r+b --
855
856Warning: fputcsv(): delimiter must be a character in %s on line %d
857bool(false)
858int(0)
859bool(false)
860string(0) ""
861
862-- file opened in r+t --
863
864Warning: fputcsv(): delimiter must be a character in %s on line %d
865bool(false)
866int(0)
867bool(false)
868string(0) ""
869
870-- file opened in a+ --
871
872Warning: fputcsv(): delimiter must be a character in %s on line %d
873bool(false)
874int(0)
875bool(false)
876string(0) ""
877
878-- file opened in a+b --
879
880Warning: fputcsv(): delimiter must be a character in %s on line %d
881bool(false)
882int(0)
883bool(false)
884string(0) ""
885
886-- file opened in a+t --
887
888Warning: fputcsv(): delimiter must be a character in %s on line %d
889bool(false)
890int(0)
891bool(false)
892string(0) ""
893
894-- file opened in w+ --
895
896Warning: fputcsv(): delimiter must be a character in %s on line %d
897bool(false)
898int(0)
899bool(false)
900string(0) ""
901
902-- file opened in w+b --
903
904Warning: fputcsv(): delimiter must be a character in %s on line %d
905bool(false)
906int(0)
907bool(false)
908string(0) ""
909
910-- file opened in w+t --
911
912Warning: fputcsv(): delimiter must be a character in %s on line %d
913bool(false)
914int(0)
915bool(false)
916string(0) ""
917
918-- file opened in x+ --
919
920Warning: fputcsv(): delimiter must be a character in %s on line %d
921bool(false)
922int(0)
923bool(false)
924string(0) ""
925
926-- file opened in x+b --
927
928Warning: fputcsv(): delimiter must be a character in %s on line %d
929bool(false)
930int(0)
931bool(false)
932string(0) ""
933
934-- file opened in x+t --
935
936Warning: fputcsv(): delimiter must be a character in %s on line %d
937bool(false)
938int(0)
939bool(false)
940string(0) ""
941Done
942
943