Annotation of embedaddon/php/ext/standard/tests/file/fscanf_variation25.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fscanf() function: usage variations - char formats with boolean
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 boolean data using different char format types */
12:
13: $file_path = dirname(__FILE__);
14:
15: echo "*** Test fscanf(): different char format types with boolean data ***\n";
16:
17: // create a file
18: $filename = "$file_path/fscanf_variation25.tmp";
19: $file_handle = fopen($filename, "w");
20: if($file_handle == false)
21: exit("Error:failed to open file $filename");
22:
23: // array of boolean types
24: $bool_types = array (
25: true,
26: false,
27: TRUE,
28: FALSE,
29: );
30:
31: $char_formats = array( "%c",
32: "%hc", "%lc", "%Lc",
33: " %c", "%c ", "% c",
34: "\t%c", "\n%c", "%4c",
35: "%30c", "%[a-zA-Z@#$&0-9]", "%*c");
36:
37: $counter = 1;
38:
39: // writing to the file
40: foreach($bool_types as $value) {
41: @fprintf($file_handle, $value);
42: @fprintf($file_handle, "\n");
43: }
44: // closing the file
45: fclose($file_handle);
46:
47: // opening the file for reading
48: $file_handle = fopen($filename, "r");
49: if($file_handle == false) {
50: exit("Error:failed to open file $filename");
51: }
52:
53: $counter = 1;
54: // reading the values from file using different char formats
55: foreach($char_formats as $char_format) {
56: // rewind the file so that for every foreach iteration the file pointer starts from bof
57: rewind($file_handle);
58: echo "\n-- iteration $counter --\n";
59: while( !feof($file_handle) ) {
60: var_dump( fscanf($file_handle,$char_format) );
61: }
62: $counter++;
63: }
64:
65: echo "\n*** Done ***";
66: ?>
67: --CLEAN--
68: <?php
69: $file_path = dirname(__FILE__);
70: $filename = "$file_path/fscanf_variation25.tmp";
71: unlink($filename);
72: ?>
73: --EXPECTF--
74: *** Test fscanf(): different char format types with boolean data ***
75:
76: -- iteration 1 --
77: array(1) {
78: [0]=>
79: string(1) "1"
80: }
81: array(1) {
82: [0]=>
83: string(0) ""
84: }
85: array(1) {
86: [0]=>
87: string(1) "1"
88: }
89: array(1) {
90: [0]=>
91: string(0) ""
92: }
93: bool(false)
94:
95: -- iteration 2 --
96: array(1) {
97: [0]=>
98: string(1) "1"
99: }
100: array(1) {
101: [0]=>
102: string(0) ""
103: }
104: array(1) {
105: [0]=>
106: string(1) "1"
107: }
108: array(1) {
109: [0]=>
110: string(0) ""
111: }
112: bool(false)
113:
114: -- iteration 3 --
115: array(1) {
116: [0]=>
117: string(1) "1"
118: }
119: array(1) {
120: [0]=>
121: string(0) ""
122: }
123: array(1) {
124: [0]=>
125: string(1) "1"
126: }
127: array(1) {
128: [0]=>
129: string(0) ""
130: }
131: bool(false)
132:
133: -- iteration 4 --
134: array(1) {
135: [0]=>
136: string(1) "1"
137: }
138: array(1) {
139: [0]=>
140: string(0) ""
141: }
142: array(1) {
143: [0]=>
144: string(1) "1"
145: }
146: array(1) {
147: [0]=>
148: string(0) ""
149: }
150: bool(false)
151:
152: -- iteration 5 --
153: array(1) {
154: [0]=>
155: string(1) "1"
156: }
157: NULL
158: array(1) {
159: [0]=>
160: string(1) "1"
161: }
162: NULL
163: bool(false)
164:
165: -- iteration 6 --
166: array(1) {
167: [0]=>
168: string(1) "1"
169: }
170: array(1) {
171: [0]=>
172: string(0) ""
173: }
174: array(1) {
175: [0]=>
176: string(1) "1"
177: }
178: array(1) {
179: [0]=>
180: string(0) ""
181: }
182: bool(false)
183:
184: -- iteration 7 --
185:
186: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
187: NULL
188:
189: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
190: NULL
191:
192: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
193: NULL
194:
195: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
196: NULL
197: bool(false)
198:
199: -- iteration 8 --
200: array(1) {
201: [0]=>
202: string(1) "1"
203: }
204: NULL
205: array(1) {
206: [0]=>
207: string(1) "1"
208: }
209: NULL
210: bool(false)
211:
212: -- iteration 9 --
213: array(1) {
214: [0]=>
215: string(1) "1"
216: }
217: NULL
218: array(1) {
219: [0]=>
220: string(1) "1"
221: }
222: NULL
223: bool(false)
224:
225: -- iteration 10 --
226: array(1) {
227: [0]=>
228: string(1) "1"
229: }
230: array(1) {
231: [0]=>
232: string(0) ""
233: }
234: array(1) {
235: [0]=>
236: string(1) "1"
237: }
238: array(1) {
239: [0]=>
240: string(0) ""
241: }
242: bool(false)
243:
244: -- iteration 11 --
245: array(1) {
246: [0]=>
247: string(1) "1"
248: }
249: array(1) {
250: [0]=>
251: string(0) ""
252: }
253: array(1) {
254: [0]=>
255: string(1) "1"
256: }
257: array(1) {
258: [0]=>
259: string(0) ""
260: }
261: bool(false)
262:
263: -- iteration 12 --
264: array(1) {
265: [0]=>
266: string(1) "1"
267: }
268: array(1) {
269: [0]=>
270: NULL
271: }
272: array(1) {
273: [0]=>
274: string(1) "1"
275: }
276: array(1) {
277: [0]=>
278: NULL
279: }
280: bool(false)
281:
282: -- iteration 13 --
283: array(0) {
284: }
285: array(0) {
286: }
287: array(0) {
288: }
289: array(0) {
290: }
291: bool(false)
292:
293: *** Done ***
294:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>