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