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