Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation29.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test fgetcsv() : usage variations - with only file handle as argument, 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 only file handle in its argument
13: */
14:
15: echo "*** Testing fgetcsv() : with file handle as only argument and 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_variation29.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: var_dump( fgetcsv($file_handle) );
76: // check the file pointer position and if eof
77: var_dump( ftell($file_handle) );
78: var_dump( feof($file_handle) );
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: --EXPECTF--
89: *** Testing fgetcsv() : with file handle as only argument and file pointer pointing at end of file ***
90:
91: -- Testing fgetcsv() with file opened using r mode --
92: int(0)
93: bool(false)
94: bool(false)
95: int(53)
96: bool(true)
97:
98: -- Testing fgetcsv() with file opened using rb mode --
99: int(0)
100: bool(false)
101: bool(false)
102: int(53)
103: bool(true)
104:
105: -- Testing fgetcsv() with file opened using rt mode --
106: int(0)
107: bool(false)
108: bool(false)
109: int(%d)
110: bool(true)
111:
112: -- Testing fgetcsv() with file opened using r+ mode --
113: int(0)
114: bool(false)
115: bool(false)
116: int(53)
117: bool(true)
118:
119: -- Testing fgetcsv() with file opened using r+b mode --
120: int(0)
121: bool(false)
122: bool(false)
123: int(53)
124: bool(true)
125:
126: -- Testing fgetcsv() with file opened using r+t mode --
127: int(0)
128: bool(false)
129: bool(false)
130: int(%d)
131: bool(true)
132:
133: -- Testing fgetcsv() with file opened using a+ mode --
134: int(0)
135: bool(false)
136: bool(false)
137: int(53)
138: bool(true)
139:
140: -- Testing fgetcsv() with file opened using a+b mode --
141: int(0)
142: bool(false)
143: bool(false)
144: int(53)
145: bool(true)
146:
147: -- Testing fgetcsv() with file opened using a+t mode --
148: int(0)
149: bool(false)
150: bool(false)
151: int(%d)
152: bool(true)
153:
154: -- Testing fgetcsv() with file opened using w+ mode --
155: int(0)
156: bool(false)
157: bool(false)
158: int(53)
159: bool(true)
160:
161: -- Testing fgetcsv() with file opened using w+b mode --
162: int(0)
163: bool(false)
164: bool(false)
165: int(53)
166: bool(true)
167:
168: -- Testing fgetcsv() with file opened using w+t mode --
169: int(0)
170: bool(false)
171: bool(false)
172: int(%d)
173: bool(true)
174:
175: -- Testing fgetcsv() with file opened using x+ mode --
176: int(0)
177: bool(false)
178: bool(false)
179: int(53)
180: bool(true)
181:
182: -- Testing fgetcsv() with file opened using x+b mode --
183: int(0)
184: bool(false)
185: bool(false)
186: int(53)
187: bool(true)
188:
189: -- Testing fgetcsv() with file opened using x+t mode --
190: int(0)
191: bool(false)
192: bool(false)
193: int(%d)
194: bool(true)
195:
196: -- Testing fgetcsv() with file opened using r mode --
197: int(0)
198: bool(false)
199: bool(false)
200: int(53)
201: bool(true)
202:
203: -- Testing fgetcsv() with file opened using rb mode --
204: int(0)
205: bool(false)
206: bool(false)
207: int(53)
208: bool(true)
209:
210: -- Testing fgetcsv() with file opened using rt mode --
211: int(0)
212: bool(false)
213: bool(false)
214: int(%d)
215: bool(true)
216:
217: -- Testing fgetcsv() with file opened using r+ mode --
218: int(0)
219: bool(false)
220: bool(false)
221: int(53)
222: bool(true)
223:
224: -- Testing fgetcsv() with file opened using r+b mode --
225: int(0)
226: bool(false)
227: bool(false)
228: int(53)
229: bool(true)
230:
231: -- Testing fgetcsv() with file opened using r+t mode --
232: int(0)
233: bool(false)
234: bool(false)
235: int(%d)
236: bool(true)
237:
238: -- Testing fgetcsv() with file opened using a+ mode --
239: int(0)
240: bool(false)
241: bool(false)
242: int(53)
243: bool(true)
244:
245: -- Testing fgetcsv() with file opened using a+b mode --
246: int(0)
247: bool(false)
248: bool(false)
249: int(53)
250: bool(true)
251:
252: -- Testing fgetcsv() with file opened using a+t mode --
253: int(0)
254: bool(false)
255: bool(false)
256: int(%d)
257: bool(true)
258:
259: -- Testing fgetcsv() with file opened using w+ mode --
260: int(0)
261: bool(false)
262: bool(false)
263: int(53)
264: bool(true)
265:
266: -- Testing fgetcsv() with file opened using w+b mode --
267: int(0)
268: bool(false)
269: bool(false)
270: int(53)
271: bool(true)
272:
273: -- Testing fgetcsv() with file opened using w+t mode --
274: int(0)
275: bool(false)
276: bool(false)
277: int(%d)
278: bool(true)
279:
280: -- Testing fgetcsv() with file opened using x+ mode --
281: int(0)
282: bool(false)
283: bool(false)
284: int(53)
285: bool(true)
286:
287: -- Testing fgetcsv() with file opened using x+b mode --
288: int(0)
289: bool(false)
290: bool(false)
291: int(53)
292: bool(true)
293:
294: -- Testing fgetcsv() with file opened using x+t mode --
295: int(0)
296: bool(false)
297: bool(false)
298: int(%d)
299: bool(true)
300:
301: -- Testing fgetcsv() with file opened using r mode --
302: int(0)
303: bool(false)
304: bool(false)
305: int(57)
306: bool(true)
307:
308: -- Testing fgetcsv() with file opened using rb mode --
309: int(0)
310: bool(false)
311: bool(false)
312: int(57)
313: bool(true)
314:
315: -- Testing fgetcsv() with file opened using rt mode --
316: int(0)
317: bool(false)
318: bool(false)
319: int(%d)
320: bool(true)
321:
322: -- Testing fgetcsv() with file opened using r+ mode --
323: int(0)
324: bool(false)
325: bool(false)
326: int(57)
327: bool(true)
328:
329: -- Testing fgetcsv() with file opened using r+b mode --
330: int(0)
331: bool(false)
332: bool(false)
333: int(57)
334: bool(true)
335:
336: -- Testing fgetcsv() with file opened using r+t mode --
337: int(0)
338: bool(false)
339: bool(false)
340: int(%d)
341: bool(true)
342:
343: -- Testing fgetcsv() with file opened using a+ mode --
344: int(0)
345: bool(false)
346: bool(false)
347: int(57)
348: bool(true)
349:
350: -- Testing fgetcsv() with file opened using a+b mode --
351: int(0)
352: bool(false)
353: bool(false)
354: int(57)
355: bool(true)
356:
357: -- Testing fgetcsv() with file opened using a+t mode --
358: int(0)
359: bool(false)
360: bool(false)
361: int(%d)
362: bool(true)
363:
364: -- Testing fgetcsv() with file opened using w+ mode --
365: int(0)
366: bool(false)
367: bool(false)
368: int(57)
369: bool(true)
370:
371: -- Testing fgetcsv() with file opened using w+b mode --
372: int(0)
373: bool(false)
374: bool(false)
375: int(57)
376: bool(true)
377:
378: -- Testing fgetcsv() with file opened using w+t mode --
379: int(0)
380: bool(false)
381: bool(false)
382: int(%d)
383: bool(true)
384:
385: -- Testing fgetcsv() with file opened using x+ mode --
386: int(0)
387: bool(false)
388: bool(false)
389: int(57)
390: bool(true)
391:
392: -- Testing fgetcsv() with file opened using x+b mode --
393: int(0)
394: bool(false)
395: bool(false)
396: int(57)
397: bool(true)
398:
399: -- Testing fgetcsv() with file opened using x+t mode --
400: int(0)
401: bool(false)
402: bool(false)
403: int(%d)
404: bool(true)
405:
406: -- Testing fgetcsv() with file opened using r mode --
407: int(0)
408: bool(false)
409: bool(false)
410: int(61)
411: bool(true)
412:
413: -- Testing fgetcsv() with file opened using rb mode --
414: int(0)
415: bool(false)
416: bool(false)
417: int(61)
418: bool(true)
419:
420: -- Testing fgetcsv() with file opened using rt mode --
421: int(0)
422: bool(false)
423: bool(false)
424: int(%d)
425: bool(true)
426:
427: -- Testing fgetcsv() with file opened using r+ mode --
428: int(0)
429: bool(false)
430: bool(false)
431: int(61)
432: bool(true)
433:
434: -- Testing fgetcsv() with file opened using r+b mode --
435: int(0)
436: bool(false)
437: bool(false)
438: int(61)
439: bool(true)
440:
441: -- Testing fgetcsv() with file opened using r+t mode --
442: int(0)
443: bool(false)
444: bool(false)
445: int(%d)
446: bool(true)
447:
448: -- Testing fgetcsv() with file opened using a+ mode --
449: int(0)
450: bool(false)
451: bool(false)
452: int(61)
453: bool(true)
454:
455: -- Testing fgetcsv() with file opened using a+b mode --
456: int(0)
457: bool(false)
458: bool(false)
459: int(61)
460: bool(true)
461:
462: -- Testing fgetcsv() with file opened using a+t mode --
463: int(0)
464: bool(false)
465: bool(false)
466: int(%d)
467: bool(true)
468:
469: -- Testing fgetcsv() with file opened using w+ mode --
470: int(0)
471: bool(false)
472: bool(false)
473: int(61)
474: bool(true)
475:
476: -- Testing fgetcsv() with file opened using w+b mode --
477: int(0)
478: bool(false)
479: bool(false)
480: int(61)
481: bool(true)
482:
483: -- Testing fgetcsv() with file opened using w+t mode --
484: int(0)
485: bool(false)
486: bool(false)
487: int(%d)
488: bool(true)
489:
490: -- Testing fgetcsv() with file opened using x+ mode --
491: int(0)
492: bool(false)
493: bool(false)
494: int(61)
495: bool(true)
496:
497: -- Testing fgetcsv() with file opened using x+b mode --
498: int(0)
499: bool(false)
500: bool(false)
501: int(61)
502: bool(true)
503:
504: -- Testing fgetcsv() with file opened using x+t mode --
505: int(0)
506: bool(false)
507: bool(false)
508: int(%d)
509: bool(true)
510:
511: -- Testing fgetcsv() with file opened using r mode --
512: int(0)
513: bool(false)
514: bool(false)
515: int(61)
516: bool(true)
517:
518: -- Testing fgetcsv() with file opened using rb mode --
519: int(0)
520: bool(false)
521: bool(false)
522: int(61)
523: bool(true)
524:
525: -- Testing fgetcsv() with file opened using rt mode --
526: int(0)
527: bool(false)
528: bool(false)
529: int(%d)
530: bool(true)
531:
532: -- Testing fgetcsv() with file opened using r+ mode --
533: int(0)
534: bool(false)
535: bool(false)
536: int(61)
537: bool(true)
538:
539: -- Testing fgetcsv() with file opened using r+b mode --
540: int(0)
541: bool(false)
542: bool(false)
543: int(61)
544: bool(true)
545:
546: -- Testing fgetcsv() with file opened using r+t mode --
547: int(0)
548: bool(false)
549: bool(false)
550: int(%d)
551: bool(true)
552:
553: -- Testing fgetcsv() with file opened using a+ mode --
554: int(0)
555: bool(false)
556: bool(false)
557: int(61)
558: bool(true)
559:
560: -- Testing fgetcsv() with file opened using a+b mode --
561: int(0)
562: bool(false)
563: bool(false)
564: int(61)
565: bool(true)
566:
567: -- Testing fgetcsv() with file opened using a+t mode --
568: int(0)
569: bool(false)
570: bool(false)
571: int(%d)
572: bool(true)
573:
574: -- Testing fgetcsv() with file opened using w+ mode --
575: int(0)
576: bool(false)
577: bool(false)
578: int(61)
579: bool(true)
580:
581: -- Testing fgetcsv() with file opened using w+b mode --
582: int(0)
583: bool(false)
584: bool(false)
585: int(61)
586: bool(true)
587:
588: -- Testing fgetcsv() with file opened using w+t mode --
589: int(0)
590: bool(false)
591: bool(false)
592: int(%d)
593: bool(true)
594:
595: -- Testing fgetcsv() with file opened using x+ mode --
596: int(0)
597: bool(false)
598: bool(false)
599: int(61)
600: bool(true)
601:
602: -- Testing fgetcsv() with file opened using x+b mode --
603: int(0)
604: bool(false)
605: bool(false)
606: int(61)
607: bool(true)
608:
609: -- Testing fgetcsv() with file opened using x+t mode --
610: int(0)
611: bool(false)
612: bool(false)
613: int(%d)
614: bool(true)
615: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>