Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation18.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test fgetcsv() : usage variations - with default enclosure and different delimiter
3: --FILE--
4: <?php
5: /*
6: Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
7: Description: Gets line from file pointer and parse for CSV fields
8: */
9:
10: /* Testing fgetcsv() to read a file when provided with default enclosure character
11: and with delimiter character which is not in the line being read by fgetcsv()
12: */
13:
14: echo "*** Testing fgetcsv() : with default enclosure and different delimiter ***\n";
15:
16: /* the array is with two elements in it. Each element should be read as
17: 1st element is delimiter & 2nd element is csv fields
18: */
19: $csv_lists = array (
20: array(',', 'water,fruit'),
21: array(' ', 'water fruit'),
22: array(' ', '"water" "fruit"'),
23: array('\\', 'water\\"fruit"\\"air"'),
24: array('\\', '"water"\\"fruit"\\"""'),
25: );
26:
27: $filename = dirname(__FILE__) . '/fgetcsv_variation18.tmp';
28: @unlink($filename);
29:
30: $file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
31: "a+", "a+b", "a+t",
32: "w+", "w+b", "w+t",
33: "x+", "x+b", "x+t");
34:
35: $loop_counter = 1;
36: foreach ($csv_lists as $csv_list) {
37: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
38: // create the file and add the content with has csv fields
39: if ( strstr($file_modes[$mode_counter], "r") ) {
40: $file_handle = fopen($filename, "w");
41: } else {
42: $file_handle = fopen($filename, $file_modes[$mode_counter] );
43: }
44: if ( !$file_handle ) {
45: echo "Error: failed to create file $filename!\n";
46: exit();
47: }
48: $delimiter = $csv_list[0];
49: $csv_field = $csv_list[1];
50: fwrite($file_handle, $csv_field . "\n");
51: // write another line of text and a blank line
52: // this will be used to test, if the fgetcsv() read more than a line and its
53: // working when only a blank line is read
54: fwrite($file_handle, "This is line of text without csv fields\n");
55: fwrite($file_handle, "\n"); // blank line
56:
57: // close the file if the mode to be used is read mode and re-open using read mode
1.1.1.2 ! misho 58: // else rewind the file pointer to beginning of the file
1.1 misho 59: if ( strstr($file_modes[$mode_counter], "r" ) ) {
60: fclose($file_handle);
61: $file_handle = fopen($filename, $file_modes[$mode_counter]);
62: } else {
63: // rewind the file pointer to bof
64: rewind($file_handle);
65: }
66:
67: echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
68:
69: // call fgetcsv() to parse csv fields
70:
71: // use different delimiter than existing in file
72: fseek($file_handle, 0, SEEK_SET);
73: $del = "+";
74: var_dump( fgetcsv($file_handle, 1024, $del) );
75: // check the file pointer position and if eof
76: var_dump( ftell($file_handle) );
77: var_dump( feof($file_handle) );
78:
79: // close the file
80: fclose($file_handle);
81: //delete file
82: unlink($filename);
83: } //end of mode loop
84: } // end of foreach
85:
86: echo "Done\n";
87: ?>
88: --EXPECT--
89: *** Testing fgetcsv() : with default enclosure and different delimiter ***
90:
91: -- Testing fgetcsv() with file opened using r mode --
92: array(1) {
93: [0]=>
94: string(11) "water,fruit"
95: }
96: int(12)
97: bool(false)
98:
99: -- Testing fgetcsv() with file opened using rb mode --
100: array(1) {
101: [0]=>
102: string(11) "water,fruit"
103: }
104: int(12)
105: bool(false)
106:
107: -- Testing fgetcsv() with file opened using rt mode --
108: array(1) {
109: [0]=>
110: string(11) "water,fruit"
111: }
112: int(12)
113: bool(false)
114:
115: -- Testing fgetcsv() with file opened using r+ mode --
116: array(1) {
117: [0]=>
118: string(11) "water,fruit"
119: }
120: int(12)
121: bool(false)
122:
123: -- Testing fgetcsv() with file opened using r+b mode --
124: array(1) {
125: [0]=>
126: string(11) "water,fruit"
127: }
128: int(12)
129: bool(false)
130:
131: -- Testing fgetcsv() with file opened using r+t mode --
132: array(1) {
133: [0]=>
134: string(11) "water,fruit"
135: }
136: int(12)
137: bool(false)
138:
139: -- Testing fgetcsv() with file opened using a+ mode --
140: array(1) {
141: [0]=>
142: string(11) "water,fruit"
143: }
144: int(12)
145: bool(false)
146:
147: -- Testing fgetcsv() with file opened using a+b mode --
148: array(1) {
149: [0]=>
150: string(11) "water,fruit"
151: }
152: int(12)
153: bool(false)
154:
155: -- Testing fgetcsv() with file opened using a+t mode --
156: array(1) {
157: [0]=>
158: string(11) "water,fruit"
159: }
160: int(12)
161: bool(false)
162:
163: -- Testing fgetcsv() with file opened using w+ mode --
164: array(1) {
165: [0]=>
166: string(11) "water,fruit"
167: }
168: int(12)
169: bool(false)
170:
171: -- Testing fgetcsv() with file opened using w+b mode --
172: array(1) {
173: [0]=>
174: string(11) "water,fruit"
175: }
176: int(12)
177: bool(false)
178:
179: -- Testing fgetcsv() with file opened using w+t mode --
180: array(1) {
181: [0]=>
182: string(11) "water,fruit"
183: }
184: int(12)
185: bool(false)
186:
187: -- Testing fgetcsv() with file opened using x+ mode --
188: array(1) {
189: [0]=>
190: string(11) "water,fruit"
191: }
192: int(12)
193: bool(false)
194:
195: -- Testing fgetcsv() with file opened using x+b mode --
196: array(1) {
197: [0]=>
198: string(11) "water,fruit"
199: }
200: int(12)
201: bool(false)
202:
203: -- Testing fgetcsv() with file opened using x+t mode --
204: array(1) {
205: [0]=>
206: string(11) "water,fruit"
207: }
208: int(12)
209: bool(false)
210:
211: -- Testing fgetcsv() with file opened using r mode --
212: array(1) {
213: [0]=>
214: string(11) "water fruit"
215: }
216: int(12)
217: bool(false)
218:
219: -- Testing fgetcsv() with file opened using rb mode --
220: array(1) {
221: [0]=>
222: string(11) "water fruit"
223: }
224: int(12)
225: bool(false)
226:
227: -- Testing fgetcsv() with file opened using rt mode --
228: array(1) {
229: [0]=>
230: string(11) "water fruit"
231: }
232: int(12)
233: bool(false)
234:
235: -- Testing fgetcsv() with file opened using r+ mode --
236: array(1) {
237: [0]=>
238: string(11) "water fruit"
239: }
240: int(12)
241: bool(false)
242:
243: -- Testing fgetcsv() with file opened using r+b mode --
244: array(1) {
245: [0]=>
246: string(11) "water fruit"
247: }
248: int(12)
249: bool(false)
250:
251: -- Testing fgetcsv() with file opened using r+t mode --
252: array(1) {
253: [0]=>
254: string(11) "water fruit"
255: }
256: int(12)
257: bool(false)
258:
259: -- Testing fgetcsv() with file opened using a+ mode --
260: array(1) {
261: [0]=>
262: string(11) "water fruit"
263: }
264: int(12)
265: bool(false)
266:
267: -- Testing fgetcsv() with file opened using a+b mode --
268: array(1) {
269: [0]=>
270: string(11) "water fruit"
271: }
272: int(12)
273: bool(false)
274:
275: -- Testing fgetcsv() with file opened using a+t mode --
276: array(1) {
277: [0]=>
278: string(11) "water fruit"
279: }
280: int(12)
281: bool(false)
282:
283: -- Testing fgetcsv() with file opened using w+ mode --
284: array(1) {
285: [0]=>
286: string(11) "water fruit"
287: }
288: int(12)
289: bool(false)
290:
291: -- Testing fgetcsv() with file opened using w+b mode --
292: array(1) {
293: [0]=>
294: string(11) "water fruit"
295: }
296: int(12)
297: bool(false)
298:
299: -- Testing fgetcsv() with file opened using w+t mode --
300: array(1) {
301: [0]=>
302: string(11) "water fruit"
303: }
304: int(12)
305: bool(false)
306:
307: -- Testing fgetcsv() with file opened using x+ mode --
308: array(1) {
309: [0]=>
310: string(11) "water fruit"
311: }
312: int(12)
313: bool(false)
314:
315: -- Testing fgetcsv() with file opened using x+b mode --
316: array(1) {
317: [0]=>
318: string(11) "water fruit"
319: }
320: int(12)
321: bool(false)
322:
323: -- Testing fgetcsv() with file opened using x+t mode --
324: array(1) {
325: [0]=>
326: string(11) "water fruit"
327: }
328: int(12)
329: bool(false)
330:
331: -- Testing fgetcsv() with file opened using r mode --
332: array(1) {
333: [0]=>
334: string(13) "water "fruit""
335: }
336: int(16)
337: bool(false)
338:
339: -- Testing fgetcsv() with file opened using rb mode --
340: array(1) {
341: [0]=>
342: string(13) "water "fruit""
343: }
344: int(16)
345: bool(false)
346:
347: -- Testing fgetcsv() with file opened using rt mode --
348: array(1) {
349: [0]=>
350: string(13) "water "fruit""
351: }
352: int(16)
353: bool(false)
354:
355: -- Testing fgetcsv() with file opened using r+ mode --
356: array(1) {
357: [0]=>
358: string(13) "water "fruit""
359: }
360: int(16)
361: bool(false)
362:
363: -- Testing fgetcsv() with file opened using r+b mode --
364: array(1) {
365: [0]=>
366: string(13) "water "fruit""
367: }
368: int(16)
369: bool(false)
370:
371: -- Testing fgetcsv() with file opened using r+t mode --
372: array(1) {
373: [0]=>
374: string(13) "water "fruit""
375: }
376: int(16)
377: bool(false)
378:
379: -- Testing fgetcsv() with file opened using a+ mode --
380: array(1) {
381: [0]=>
382: string(13) "water "fruit""
383: }
384: int(16)
385: bool(false)
386:
387: -- Testing fgetcsv() with file opened using a+b mode --
388: array(1) {
389: [0]=>
390: string(13) "water "fruit""
391: }
392: int(16)
393: bool(false)
394:
395: -- Testing fgetcsv() with file opened using a+t mode --
396: array(1) {
397: [0]=>
398: string(13) "water "fruit""
399: }
400: int(16)
401: bool(false)
402:
403: -- Testing fgetcsv() with file opened using w+ mode --
404: array(1) {
405: [0]=>
406: string(13) "water "fruit""
407: }
408: int(16)
409: bool(false)
410:
411: -- Testing fgetcsv() with file opened using w+b mode --
412: array(1) {
413: [0]=>
414: string(13) "water "fruit""
415: }
416: int(16)
417: bool(false)
418:
419: -- Testing fgetcsv() with file opened using w+t mode --
420: array(1) {
421: [0]=>
422: string(13) "water "fruit""
423: }
424: int(16)
425: bool(false)
426:
427: -- Testing fgetcsv() with file opened using x+ mode --
428: array(1) {
429: [0]=>
430: string(13) "water "fruit""
431: }
432: int(16)
433: bool(false)
434:
435: -- Testing fgetcsv() with file opened using x+b mode --
436: array(1) {
437: [0]=>
438: string(13) "water "fruit""
439: }
440: int(16)
441: bool(false)
442:
443: -- Testing fgetcsv() with file opened using x+t mode --
444: array(1) {
445: [0]=>
446: string(13) "water "fruit""
447: }
448: int(16)
449: bool(false)
450:
451: -- Testing fgetcsv() with file opened using r mode --
452: array(1) {
453: [0]=>
454: string(19) "water\"fruit"\"air""
455: }
456: int(20)
457: bool(false)
458:
459: -- Testing fgetcsv() with file opened using rb mode --
460: array(1) {
461: [0]=>
462: string(19) "water\"fruit"\"air""
463: }
464: int(20)
465: bool(false)
466:
467: -- Testing fgetcsv() with file opened using rt mode --
468: array(1) {
469: [0]=>
470: string(19) "water\"fruit"\"air""
471: }
472: int(20)
473: bool(false)
474:
475: -- Testing fgetcsv() with file opened using r+ mode --
476: array(1) {
477: [0]=>
478: string(19) "water\"fruit"\"air""
479: }
480: int(20)
481: bool(false)
482:
483: -- Testing fgetcsv() with file opened using r+b mode --
484: array(1) {
485: [0]=>
486: string(19) "water\"fruit"\"air""
487: }
488: int(20)
489: bool(false)
490:
491: -- Testing fgetcsv() with file opened using r+t mode --
492: array(1) {
493: [0]=>
494: string(19) "water\"fruit"\"air""
495: }
496: int(20)
497: bool(false)
498:
499: -- Testing fgetcsv() with file opened using a+ mode --
500: array(1) {
501: [0]=>
502: string(19) "water\"fruit"\"air""
503: }
504: int(20)
505: bool(false)
506:
507: -- Testing fgetcsv() with file opened using a+b mode --
508: array(1) {
509: [0]=>
510: string(19) "water\"fruit"\"air""
511: }
512: int(20)
513: bool(false)
514:
515: -- Testing fgetcsv() with file opened using a+t mode --
516: array(1) {
517: [0]=>
518: string(19) "water\"fruit"\"air""
519: }
520: int(20)
521: bool(false)
522:
523: -- Testing fgetcsv() with file opened using w+ mode --
524: array(1) {
525: [0]=>
526: string(19) "water\"fruit"\"air""
527: }
528: int(20)
529: bool(false)
530:
531: -- Testing fgetcsv() with file opened using w+b mode --
532: array(1) {
533: [0]=>
534: string(19) "water\"fruit"\"air""
535: }
536: int(20)
537: bool(false)
538:
539: -- Testing fgetcsv() with file opened using w+t mode --
540: array(1) {
541: [0]=>
542: string(19) "water\"fruit"\"air""
543: }
544: int(20)
545: bool(false)
546:
547: -- Testing fgetcsv() with file opened using x+ mode --
548: array(1) {
549: [0]=>
550: string(19) "water\"fruit"\"air""
551: }
552: int(20)
553: bool(false)
554:
555: -- Testing fgetcsv() with file opened using x+b mode --
556: array(1) {
557: [0]=>
558: string(19) "water\"fruit"\"air""
559: }
560: int(20)
561: bool(false)
562:
563: -- Testing fgetcsv() with file opened using x+t mode --
564: array(1) {
565: [0]=>
566: string(19) "water\"fruit"\"air""
567: }
568: int(20)
569: bool(false)
570:
571: -- Testing fgetcsv() with file opened using r mode --
572: array(1) {
573: [0]=>
574: string(17) "water\"fruit"\""""
575: }
576: int(20)
577: bool(false)
578:
579: -- Testing fgetcsv() with file opened using rb mode --
580: array(1) {
581: [0]=>
582: string(17) "water\"fruit"\""""
583: }
584: int(20)
585: bool(false)
586:
587: -- Testing fgetcsv() with file opened using rt mode --
588: array(1) {
589: [0]=>
590: string(17) "water\"fruit"\""""
591: }
592: int(20)
593: bool(false)
594:
595: -- Testing fgetcsv() with file opened using r+ mode --
596: array(1) {
597: [0]=>
598: string(17) "water\"fruit"\""""
599: }
600: int(20)
601: bool(false)
602:
603: -- Testing fgetcsv() with file opened using r+b mode --
604: array(1) {
605: [0]=>
606: string(17) "water\"fruit"\""""
607: }
608: int(20)
609: bool(false)
610:
611: -- Testing fgetcsv() with file opened using r+t mode --
612: array(1) {
613: [0]=>
614: string(17) "water\"fruit"\""""
615: }
616: int(20)
617: bool(false)
618:
619: -- Testing fgetcsv() with file opened using a+ mode --
620: array(1) {
621: [0]=>
622: string(17) "water\"fruit"\""""
623: }
624: int(20)
625: bool(false)
626:
627: -- Testing fgetcsv() with file opened using a+b mode --
628: array(1) {
629: [0]=>
630: string(17) "water\"fruit"\""""
631: }
632: int(20)
633: bool(false)
634:
635: -- Testing fgetcsv() with file opened using a+t mode --
636: array(1) {
637: [0]=>
638: string(17) "water\"fruit"\""""
639: }
640: int(20)
641: bool(false)
642:
643: -- Testing fgetcsv() with file opened using w+ mode --
644: array(1) {
645: [0]=>
646: string(17) "water\"fruit"\""""
647: }
648: int(20)
649: bool(false)
650:
651: -- Testing fgetcsv() with file opened using w+b mode --
652: array(1) {
653: [0]=>
654: string(17) "water\"fruit"\""""
655: }
656: int(20)
657: bool(false)
658:
659: -- Testing fgetcsv() with file opened using w+t mode --
660: array(1) {
661: [0]=>
662: string(17) "water\"fruit"\""""
663: }
664: int(20)
665: bool(false)
666:
667: -- Testing fgetcsv() with file opened using x+ mode --
668: array(1) {
669: [0]=>
670: string(17) "water\"fruit"\""""
671: }
672: int(20)
673: bool(false)
674:
675: -- Testing fgetcsv() with file opened using x+b mode --
676: array(1) {
677: [0]=>
678: string(17) "water\"fruit"\""""
679: }
680: int(20)
681: bool(false)
682:
683: -- Testing fgetcsv() with file opened using x+t mode --
684: array(1) {
685: [0]=>
686: string(17) "water\"fruit"\""""
687: }
688: int(20)
689: bool(false)
690: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>