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