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