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