Annotation of embedaddon/php/ext/standard/tests/file/fscanf_variation24.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fscanf() function: usage variations - char formats with strings
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 strings using different char format types */
12:
13: $file_path = dirname(__FILE__);
14:
15: echo "*** Test fscanf(): different char format types with strings ***\n";
16:
17: // create a file
18: $filename = "$file_path/fscanf_variation24.tmp";
19: $file_handle = fopen($filename, "w");
20: if($file_handle == false)
21: exit("Error:failed to open file $filename");
22:
23: // array of strings
24: $strings = array (
25: "",
26: '',
27: "0",
28: '0',
29: "1",
30: '1',
31: "\x01",
32: '\x01',
33: "\01",
34: '\01',
35: 'string',
36: "string",
37: "true",
38: "FALSE",
39: 'false',
40: 'TRUE',
41: "NULL",
42: 'null'
43: );
44:
45: $char_formats = array( "%c",
46: "%hc", "%lc", "%Lc",
47: " %c", "%c ", "% c",
48: "\t%c", "\n%c", "%4c",
49: "%30c", "%[a-zA-Z@#$&0-9]", "%*c");
50:
51: $counter = 1;
52:
53: // writing to the file
54: foreach($strings as $string) {
55: @fprintf($file_handle, $string);
56: @fprintf($file_handle, "\n");
57: }
58: // closing the file
59: fclose($file_handle);
60:
61: // opening the file for reading
62: $file_handle = fopen($filename, "r");
63: if($file_handle == false) {
64: exit("Error:failed to open file $filename");
65: }
66:
67: $counter = 1;
68: // reading the values from file using different char formats
69: foreach($char_formats as $char_format) {
70: // rewind the file so that for every foreach iteration the file pointer starts from bof
71: rewind($file_handle);
72: echo "\n-- iteration $counter --\n";
73: while( !feof($file_handle) ) {
74: var_dump( fscanf($file_handle,$char_format) );
75: }
76: $counter++;
77: }
78:
79: echo "\n*** Done ***";
80: ?>
81: --CLEAN--
82: <?php
83: $file_path = dirname(__FILE__);
84: $filename = "$file_path/fscanf_variation24.tmp";
85: unlink($filename);
86: ?>
87: --EXPECTF--
88: *** Test fscanf(): different char format types with strings ***
89:
90: -- iteration 1 --
91: array(1) {
92: [0]=>
93: string(0) ""
94: }
95: array(1) {
96: [0]=>
97: string(0) ""
98: }
99: array(1) {
100: [0]=>
101: string(1) "0"
102: }
103: array(1) {
104: [0]=>
105: string(1) "0"
106: }
107: array(1) {
108: [0]=>
109: string(1) "1"
110: }
111: array(1) {
112: [0]=>
113: string(1) "1"
114: }
115: array(1) {
116: [0]=>
117: string(1) "&"
118: }
119: array(1) {
120: [0]=>
121: string(1) "\"
122: }
123: array(1) {
124: [0]=>
125: string(1) "&"
126: }
127: array(1) {
128: [0]=>
129: string(1) "\"
130: }
131: array(1) {
132: [0]=>
133: string(1) "s"
134: }
135: array(1) {
136: [0]=>
137: string(1) "s"
138: }
139: array(1) {
140: [0]=>
141: string(1) "t"
142: }
143: array(1) {
144: [0]=>
145: string(1) "F"
146: }
147: array(1) {
148: [0]=>
149: string(1) "f"
150: }
151: array(1) {
152: [0]=>
153: string(1) "T"
154: }
155: array(1) {
156: [0]=>
157: string(1) "N"
158: }
159: array(1) {
160: [0]=>
161: string(1) "n"
162: }
163: bool(false)
164:
165: -- iteration 2 --
166: array(1) {
167: [0]=>
168: string(0) ""
169: }
170: array(1) {
171: [0]=>
172: string(0) ""
173: }
174: array(1) {
175: [0]=>
176: string(1) "0"
177: }
178: array(1) {
179: [0]=>
180: string(1) "0"
181: }
182: array(1) {
183: [0]=>
184: string(1) "1"
185: }
186: array(1) {
187: [0]=>
188: string(1) "1"
189: }
190: array(1) {
191: [0]=>
192: string(1) "&"
193: }
194: array(1) {
195: [0]=>
196: string(1) "\"
197: }
198: array(1) {
199: [0]=>
200: string(1) "&"
201: }
202: array(1) {
203: [0]=>
204: string(1) "\"
205: }
206: array(1) {
207: [0]=>
208: string(1) "s"
209: }
210: array(1) {
211: [0]=>
212: string(1) "s"
213: }
214: array(1) {
215: [0]=>
216: string(1) "t"
217: }
218: array(1) {
219: [0]=>
220: string(1) "F"
221: }
222: array(1) {
223: [0]=>
224: string(1) "f"
225: }
226: array(1) {
227: [0]=>
228: string(1) "T"
229: }
230: array(1) {
231: [0]=>
232: string(1) "N"
233: }
234: array(1) {
235: [0]=>
236: string(1) "n"
237: }
238: bool(false)
239:
240: -- iteration 3 --
241: array(1) {
242: [0]=>
243: string(0) ""
244: }
245: array(1) {
246: [0]=>
247: string(0) ""
248: }
249: array(1) {
250: [0]=>
251: string(1) "0"
252: }
253: array(1) {
254: [0]=>
255: string(1) "0"
256: }
257: array(1) {
258: [0]=>
259: string(1) "1"
260: }
261: array(1) {
262: [0]=>
263: string(1) "1"
264: }
265: array(1) {
266: [0]=>
267: string(1) "&"
268: }
269: array(1) {
270: [0]=>
271: string(1) "\"
272: }
273: array(1) {
274: [0]=>
275: string(1) "&"
276: }
277: array(1) {
278: [0]=>
279: string(1) "\"
280: }
281: array(1) {
282: [0]=>
283: string(1) "s"
284: }
285: array(1) {
286: [0]=>
287: string(1) "s"
288: }
289: array(1) {
290: [0]=>
291: string(1) "t"
292: }
293: array(1) {
294: [0]=>
295: string(1) "F"
296: }
297: array(1) {
298: [0]=>
299: string(1) "f"
300: }
301: array(1) {
302: [0]=>
303: string(1) "T"
304: }
305: array(1) {
306: [0]=>
307: string(1) "N"
308: }
309: array(1) {
310: [0]=>
311: string(1) "n"
312: }
313: bool(false)
314:
315: -- iteration 4 --
316: array(1) {
317: [0]=>
318: string(0) ""
319: }
320: array(1) {
321: [0]=>
322: string(0) ""
323: }
324: array(1) {
325: [0]=>
326: string(1) "0"
327: }
328: array(1) {
329: [0]=>
330: string(1) "0"
331: }
332: array(1) {
333: [0]=>
334: string(1) "1"
335: }
336: array(1) {
337: [0]=>
338: string(1) "1"
339: }
340: array(1) {
341: [0]=>
342: string(1) "&"
343: }
344: array(1) {
345: [0]=>
346: string(1) "\"
347: }
348: array(1) {
349: [0]=>
350: string(1) "&"
351: }
352: array(1) {
353: [0]=>
354: string(1) "\"
355: }
356: array(1) {
357: [0]=>
358: string(1) "s"
359: }
360: array(1) {
361: [0]=>
362: string(1) "s"
363: }
364: array(1) {
365: [0]=>
366: string(1) "t"
367: }
368: array(1) {
369: [0]=>
370: string(1) "F"
371: }
372: array(1) {
373: [0]=>
374: string(1) "f"
375: }
376: array(1) {
377: [0]=>
378: string(1) "T"
379: }
380: array(1) {
381: [0]=>
382: string(1) "N"
383: }
384: array(1) {
385: [0]=>
386: string(1) "n"
387: }
388: bool(false)
389:
390: -- iteration 5 --
391: NULL
392: NULL
393: array(1) {
394: [0]=>
395: string(1) "0"
396: }
397: array(1) {
398: [0]=>
399: string(1) "0"
400: }
401: array(1) {
402: [0]=>
403: string(1) "1"
404: }
405: array(1) {
406: [0]=>
407: string(1) "1"
408: }
409: array(1) {
410: [0]=>
411: string(1) "&"
412: }
413: array(1) {
414: [0]=>
415: string(1) "\"
416: }
417: array(1) {
418: [0]=>
419: string(1) "&"
420: }
421: array(1) {
422: [0]=>
423: string(1) "\"
424: }
425: array(1) {
426: [0]=>
427: string(1) "s"
428: }
429: array(1) {
430: [0]=>
431: string(1) "s"
432: }
433: array(1) {
434: [0]=>
435: string(1) "t"
436: }
437: array(1) {
438: [0]=>
439: string(1) "F"
440: }
441: array(1) {
442: [0]=>
443: string(1) "f"
444: }
445: array(1) {
446: [0]=>
447: string(1) "T"
448: }
449: array(1) {
450: [0]=>
451: string(1) "N"
452: }
453: array(1) {
454: [0]=>
455: string(1) "n"
456: }
457: bool(false)
458:
459: -- iteration 6 --
460: array(1) {
461: [0]=>
462: string(0) ""
463: }
464: array(1) {
465: [0]=>
466: string(0) ""
467: }
468: array(1) {
469: [0]=>
470: string(1) "0"
471: }
472: array(1) {
473: [0]=>
474: string(1) "0"
475: }
476: array(1) {
477: [0]=>
478: string(1) "1"
479: }
480: array(1) {
481: [0]=>
482: string(1) "1"
483: }
484: array(1) {
485: [0]=>
486: string(1) "&"
487: }
488: array(1) {
489: [0]=>
490: string(1) "\"
491: }
492: array(1) {
493: [0]=>
494: string(1) "&"
495: }
496: array(1) {
497: [0]=>
498: string(1) "\"
499: }
500: array(1) {
501: [0]=>
502: string(1) "s"
503: }
504: array(1) {
505: [0]=>
506: string(1) "s"
507: }
508: array(1) {
509: [0]=>
510: string(1) "t"
511: }
512: array(1) {
513: [0]=>
514: string(1) "F"
515: }
516: array(1) {
517: [0]=>
518: string(1) "f"
519: }
520: array(1) {
521: [0]=>
522: string(1) "T"
523: }
524: array(1) {
525: [0]=>
526: string(1) "N"
527: }
528: array(1) {
529: [0]=>
530: string(1) "n"
531: }
532: bool(false)
533:
534: -- iteration 7 --
535:
536: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
537: NULL
538:
539: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
540: NULL
541:
542: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
543: NULL
544:
545: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
546: NULL
547:
548: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
549: NULL
550:
551: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
552: NULL
553:
554: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
555: NULL
556:
557: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
558: NULL
559:
560: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
561: NULL
562:
563: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
564: NULL
565:
566: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
567: NULL
568:
569: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
570: NULL
571:
572: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
573: NULL
574:
575: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
576: NULL
577:
578: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
579: NULL
580:
581: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
582: NULL
583:
584: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
585: NULL
586:
587: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
588: NULL
589: bool(false)
590:
591: -- iteration 8 --
592: NULL
593: NULL
594: array(1) {
595: [0]=>
596: string(1) "0"
597: }
598: array(1) {
599: [0]=>
600: string(1) "0"
601: }
602: array(1) {
603: [0]=>
604: string(1) "1"
605: }
606: array(1) {
607: [0]=>
608: string(1) "1"
609: }
610: array(1) {
611: [0]=>
612: string(1) "&"
613: }
614: array(1) {
615: [0]=>
616: string(1) "\"
617: }
618: array(1) {
619: [0]=>
620: string(1) "&"
621: }
622: array(1) {
623: [0]=>
624: string(1) "\"
625: }
626: array(1) {
627: [0]=>
628: string(1) "s"
629: }
630: array(1) {
631: [0]=>
632: string(1) "s"
633: }
634: array(1) {
635: [0]=>
636: string(1) "t"
637: }
638: array(1) {
639: [0]=>
640: string(1) "F"
641: }
642: array(1) {
643: [0]=>
644: string(1) "f"
645: }
646: array(1) {
647: [0]=>
648: string(1) "T"
649: }
650: array(1) {
651: [0]=>
652: string(1) "N"
653: }
654: array(1) {
655: [0]=>
656: string(1) "n"
657: }
658: bool(false)
659:
660: -- iteration 9 --
661: NULL
662: NULL
663: array(1) {
664: [0]=>
665: string(1) "0"
666: }
667: array(1) {
668: [0]=>
669: string(1) "0"
670: }
671: array(1) {
672: [0]=>
673: string(1) "1"
674: }
675: array(1) {
676: [0]=>
677: string(1) "1"
678: }
679: array(1) {
680: [0]=>
681: string(1) "&"
682: }
683: array(1) {
684: [0]=>
685: string(1) "\"
686: }
687: array(1) {
688: [0]=>
689: string(1) "&"
690: }
691: array(1) {
692: [0]=>
693: string(1) "\"
694: }
695: array(1) {
696: [0]=>
697: string(1) "s"
698: }
699: array(1) {
700: [0]=>
701: string(1) "s"
702: }
703: array(1) {
704: [0]=>
705: string(1) "t"
706: }
707: array(1) {
708: [0]=>
709: string(1) "F"
710: }
711: array(1) {
712: [0]=>
713: string(1) "f"
714: }
715: array(1) {
716: [0]=>
717: string(1) "T"
718: }
719: array(1) {
720: [0]=>
721: string(1) "N"
722: }
723: array(1) {
724: [0]=>
725: string(1) "n"
726: }
727: bool(false)
728:
729: -- iteration 10 --
730: array(1) {
731: [0]=>
732: string(0) ""
733: }
734: array(1) {
735: [0]=>
736: string(0) ""
737: }
738: array(1) {
739: [0]=>
740: string(1) "0"
741: }
742: array(1) {
743: [0]=>
744: string(1) "0"
745: }
746: array(1) {
747: [0]=>
748: string(1) "1"
749: }
750: array(1) {
751: [0]=>
752: string(1) "1"
753: }
754: array(1) {
755: [0]=>
756: string(1) "&"
757: }
758: array(1) {
759: [0]=>
760: string(4) "\x01"
761: }
762: array(1) {
763: [0]=>
764: string(1) "&"
765: }
766: array(1) {
767: [0]=>
768: string(3) "\01"
769: }
770: array(1) {
771: [0]=>
772: string(4) "stri"
773: }
774: array(1) {
775: [0]=>
776: string(4) "stri"
777: }
778: array(1) {
779: [0]=>
780: string(4) "true"
781: }
782: array(1) {
783: [0]=>
784: string(4) "FALS"
785: }
786: array(1) {
787: [0]=>
788: string(4) "fals"
789: }
790: array(1) {
791: [0]=>
792: string(4) "TRUE"
793: }
794: array(1) {
795: [0]=>
796: string(4) "NULL"
797: }
798: array(1) {
799: [0]=>
800: string(4) "null"
801: }
802: bool(false)
803:
804: -- iteration 11 --
805: array(1) {
806: [0]=>
807: string(0) ""
808: }
809: array(1) {
810: [0]=>
811: string(0) ""
812: }
813: array(1) {
814: [0]=>
815: string(1) "0"
816: }
817: array(1) {
818: [0]=>
819: string(1) "0"
820: }
821: array(1) {
822: [0]=>
823: string(1) "1"
824: }
825: array(1) {
826: [0]=>
827: string(1) "1"
828: }
829: array(1) {
830: [0]=>
831: string(1) "&"
832: }
833: array(1) {
834: [0]=>
835: string(4) "\x01"
836: }
837: array(1) {
838: [0]=>
839: string(1) "&"
840: }
841: array(1) {
842: [0]=>
843: string(3) "\01"
844: }
845: array(1) {
846: [0]=>
847: string(6) "string"
848: }
849: array(1) {
850: [0]=>
851: string(6) "string"
852: }
853: array(1) {
854: [0]=>
855: string(4) "true"
856: }
857: array(1) {
858: [0]=>
859: string(5) "FALSE"
860: }
861: array(1) {
862: [0]=>
863: string(5) "false"
864: }
865: array(1) {
866: [0]=>
867: string(4) "TRUE"
868: }
869: array(1) {
870: [0]=>
871: string(4) "NULL"
872: }
873: array(1) {
874: [0]=>
875: string(4) "null"
876: }
877: bool(false)
878:
879: -- iteration 12 --
880: array(1) {
881: [0]=>
882: NULL
883: }
884: array(1) {
885: [0]=>
886: NULL
887: }
888: array(1) {
889: [0]=>
890: string(1) "0"
891: }
892: array(1) {
893: [0]=>
894: string(1) "0"
895: }
896: array(1) {
897: [0]=>
898: string(1) "1"
899: }
900: array(1) {
901: [0]=>
902: string(1) "1"
903: }
904: array(1) {
905: [0]=>
906: NULL
907: }
908: array(1) {
909: [0]=>
910: NULL
911: }
912: array(1) {
913: [0]=>
914: NULL
915: }
916: array(1) {
917: [0]=>
918: NULL
919: }
920: array(1) {
921: [0]=>
922: string(6) "string"
923: }
924: array(1) {
925: [0]=>
926: string(6) "string"
927: }
928: array(1) {
929: [0]=>
930: string(4) "true"
931: }
932: array(1) {
933: [0]=>
934: string(5) "FALSE"
935: }
936: array(1) {
937: [0]=>
938: string(5) "false"
939: }
940: array(1) {
941: [0]=>
942: string(4) "TRUE"
943: }
944: array(1) {
945: [0]=>
946: string(4) "NULL"
947: }
948: array(1) {
949: [0]=>
950: string(4) "null"
951: }
952: bool(false)
953:
954: -- iteration 13 --
955: array(0) {
956: }
957: array(0) {
958: }
959: array(0) {
960: }
961: array(0) {
962: }
963: array(0) {
964: }
965: array(0) {
966: }
967: array(0) {
968: }
969: array(0) {
970: }
971: array(0) {
972: }
973: array(0) {
974: }
975: array(0) {
976: }
977: array(0) {
978: }
979: array(0) {
980: }
981: array(0) {
982: }
983: array(0) {
984: }
985: array(0) {
986: }
987: array(0) {
988: }
989: array(0) {
990: }
991: bool(false)
992:
993: *** Done ***
994:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>