Annotation of embedaddon/php/ext/standard/tests/file/fscanf_variation29.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fscanf() function: usage variations - octal formats with resource
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 resource type using different octal format types */
12:
13: $file_path = dirname(__FILE__);
14:
15: echo "*** Test fscanf(): different octal format types with resource ***\n";
16:
17: // create a file
18: $filename = "$file_path/fscanf_variation29.tmp";
19: $file_handle = fopen($filename, "w");
20: if($file_handle == false)
21: exit("Error:failed to open file $filename");
22:
23:
24: // resource type variable
25: $fp = fopen (__FILE__, "r");
26: $dfp = opendir ( dirname(__FILE__) );
27:
28: // array of resource types
29: $resource_types = array (
30: $fp,
31: $dfp
32: );
33:
34: $octal_formats = array( "%o",
35: "%ho", "%lo", "%Lo",
36: " %o", "%o ", "% o",
37: "\t%o", "\n%o", "%4o",
38: "%30o", "%[0-7]", "%*o"
39: );
40:
41: $counter = 1;
42:
43: // writing to the file
44: foreach($resource_types as $value) {
45: @fprintf($file_handle, $value);
46: @fprintf($file_handle, "\n");
47: }
48: // closing the file
49: fclose($file_handle);
50:
51: // opening the file for reading
52: $file_handle = fopen($filename, "r");
53: if($file_handle == false) {
54: exit("Error:failed to open file $filename");
55: }
56:
57: $counter = 1;
58: // reading the values from file using different octal formats
59: foreach($octal_formats as $octal_format) {
60: // rewind the file so that for every foreach iteration the file pointer starts from bof
61: rewind($file_handle);
62: echo "\n-- iteration $counter --\n";
63: while( !feof($file_handle) ) {
64: var_dump( fscanf($file_handle,$octal_format) );
65: }
66: $counter++;
67: }
68:
69: // closing the resources
70: fclose($fp);
71: closedir($dfp);
72:
73: echo "\n*** Done ***";
74: ?>
75: --CLEAN--
76: <?php
77: $file_path = dirname(__FILE__);
78: $filename = "$file_path/fscanf_variation29.tmp";
79: unlink($filename);
80: ?>
81: --EXPECTF--
82: *** Test fscanf(): different octal format types with resource ***
83:
84: -- iteration 1 --
85: array(1) {
86: [0]=>
87: NULL
88: }
89: array(1) {
90: [0]=>
91: NULL
92: }
93: bool(false)
94:
95: -- iteration 2 --
96: array(1) {
97: [0]=>
98: NULL
99: }
100: array(1) {
101: [0]=>
102: NULL
103: }
104: bool(false)
105:
106: -- iteration 3 --
107: array(1) {
108: [0]=>
109: NULL
110: }
111: array(1) {
112: [0]=>
113: NULL
114: }
115: bool(false)
116:
117: -- iteration 4 --
118: array(1) {
119: [0]=>
120: NULL
121: }
122: array(1) {
123: [0]=>
124: NULL
125: }
126: bool(false)
127:
128: -- iteration 5 --
129: array(1) {
130: [0]=>
131: NULL
132: }
133: array(1) {
134: [0]=>
135: NULL
136: }
137: bool(false)
138:
139: -- iteration 6 --
140: array(1) {
141: [0]=>
142: NULL
143: }
144: array(1) {
145: [0]=>
146: NULL
147: }
148: bool(false)
149:
150: -- iteration 7 --
151:
152: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
153: NULL
154:
155: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
156: NULL
157: bool(false)
158:
159: -- iteration 8 --
160: array(1) {
161: [0]=>
162: NULL
163: }
164: array(1) {
165: [0]=>
166: NULL
167: }
168: bool(false)
169:
170: -- iteration 9 --
171: array(1) {
172: [0]=>
173: NULL
174: }
175: array(1) {
176: [0]=>
177: NULL
178: }
179: bool(false)
180:
181: -- iteration 10 --
182: array(1) {
183: [0]=>
184: NULL
185: }
186: array(1) {
187: [0]=>
188: NULL
189: }
190: bool(false)
191:
192: -- iteration 11 --
193: array(1) {
194: [0]=>
195: NULL
196: }
197: array(1) {
198: [0]=>
199: NULL
200: }
201: bool(false)
202:
203: -- iteration 12 --
204: array(1) {
205: [0]=>
206: NULL
207: }
208: array(1) {
209: [0]=>
210: NULL
211: }
212: bool(false)
213:
214: -- iteration 13 --
215: array(0) {
216: }
217: array(0) {
218: }
219: bool(false)
220:
221: *** Done ***
222:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>