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