1--TEST--
2Test fscanf() function: usage variations - hexa 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 hexa format types */
12
13$file_path = dirname(__FILE__);
14
15echo "*** Test fscanf(): different hexa format types with arrays ***\n";
16
17// create a file
18$filename = "$file_path/fscanf_variation36.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$hexa_formats = array( "%x", "%hx", "%lx", "%Lx", " %x", "%x ", "% x", "\t%x", "\n%x", "%4x", "%30x", "%[0-9]", "%*x");
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 hexa formats
59foreach($hexa_formats as $hexa_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,$hexa_format) );
65  }
66  $counter++;
67}
68
69echo "\n*** Done ***";
70?>
71--CLEAN--
72<?php
73$file_path = dirname(__FILE__);
74$filename = "$file_path/fscanf_variation36.tmp";
75unlink($filename);
76?>
77--EXPECTF--
78*** Test fscanf(): different hexa format types with arrays ***
79
80-- iteration 1 --
81array(1) {
82  [0]=>
83  int(10)
84}
85array(1) {
86  [0]=>
87  int(10)
88}
89array(1) {
90  [0]=>
91  int(10)
92}
93array(1) {
94  [0]=>
95  int(10)
96}
97array(1) {
98  [0]=>
99  int(10)
100}
101array(1) {
102  [0]=>
103  int(10)
104}
105array(1) {
106  [0]=>
107  int(10)
108}
109array(1) {
110  [0]=>
111  int(10)
112}
113array(1) {
114  [0]=>
115  int(10)
116}
117array(1) {
118  [0]=>
119  int(10)
120}
121array(1) {
122  [0]=>
123  int(10)
124}
125array(1) {
126  [0]=>
127  int(10)
128}
129bool(false)
130
131-- iteration 2 --
132array(1) {
133  [0]=>
134  int(10)
135}
136array(1) {
137  [0]=>
138  int(10)
139}
140array(1) {
141  [0]=>
142  int(10)
143}
144array(1) {
145  [0]=>
146  int(10)
147}
148array(1) {
149  [0]=>
150  int(10)
151}
152array(1) {
153  [0]=>
154  int(10)
155}
156array(1) {
157  [0]=>
158  int(10)
159}
160array(1) {
161  [0]=>
162  int(10)
163}
164array(1) {
165  [0]=>
166  int(10)
167}
168array(1) {
169  [0]=>
170  int(10)
171}
172array(1) {
173  [0]=>
174  int(10)
175}
176array(1) {
177  [0]=>
178  int(10)
179}
180bool(false)
181
182-- iteration 3 --
183array(1) {
184  [0]=>
185  int(10)
186}
187array(1) {
188  [0]=>
189  int(10)
190}
191array(1) {
192  [0]=>
193  int(10)
194}
195array(1) {
196  [0]=>
197  int(10)
198}
199array(1) {
200  [0]=>
201  int(10)
202}
203array(1) {
204  [0]=>
205  int(10)
206}
207array(1) {
208  [0]=>
209  int(10)
210}
211array(1) {
212  [0]=>
213  int(10)
214}
215array(1) {
216  [0]=>
217  int(10)
218}
219array(1) {
220  [0]=>
221  int(10)
222}
223array(1) {
224  [0]=>
225  int(10)
226}
227array(1) {
228  [0]=>
229  int(10)
230}
231bool(false)
232
233-- iteration 4 --
234array(1) {
235  [0]=>
236  int(10)
237}
238array(1) {
239  [0]=>
240  int(10)
241}
242array(1) {
243  [0]=>
244  int(10)
245}
246array(1) {
247  [0]=>
248  int(10)
249}
250array(1) {
251  [0]=>
252  int(10)
253}
254array(1) {
255  [0]=>
256  int(10)
257}
258array(1) {
259  [0]=>
260  int(10)
261}
262array(1) {
263  [0]=>
264  int(10)
265}
266array(1) {
267  [0]=>
268  int(10)
269}
270array(1) {
271  [0]=>
272  int(10)
273}
274array(1) {
275  [0]=>
276  int(10)
277}
278array(1) {
279  [0]=>
280  int(10)
281}
282bool(false)
283
284-- iteration 5 --
285array(1) {
286  [0]=>
287  int(10)
288}
289array(1) {
290  [0]=>
291  int(10)
292}
293array(1) {
294  [0]=>
295  int(10)
296}
297array(1) {
298  [0]=>
299  int(10)
300}
301array(1) {
302  [0]=>
303  int(10)
304}
305array(1) {
306  [0]=>
307  int(10)
308}
309array(1) {
310  [0]=>
311  int(10)
312}
313array(1) {
314  [0]=>
315  int(10)
316}
317array(1) {
318  [0]=>
319  int(10)
320}
321array(1) {
322  [0]=>
323  int(10)
324}
325array(1) {
326  [0]=>
327  int(10)
328}
329array(1) {
330  [0]=>
331  int(10)
332}
333bool(false)
334
335-- iteration 6 --
336array(1) {
337  [0]=>
338  int(10)
339}
340array(1) {
341  [0]=>
342  int(10)
343}
344array(1) {
345  [0]=>
346  int(10)
347}
348array(1) {
349  [0]=>
350  int(10)
351}
352array(1) {
353  [0]=>
354  int(10)
355}
356array(1) {
357  [0]=>
358  int(10)
359}
360array(1) {
361  [0]=>
362  int(10)
363}
364array(1) {
365  [0]=>
366  int(10)
367}
368array(1) {
369  [0]=>
370  int(10)
371}
372array(1) {
373  [0]=>
374  int(10)
375}
376array(1) {
377  [0]=>
378  int(10)
379}
380array(1) {
381  [0]=>
382  int(10)
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  int(10)
429}
430array(1) {
431  [0]=>
432  int(10)
433}
434array(1) {
435  [0]=>
436  int(10)
437}
438array(1) {
439  [0]=>
440  int(10)
441}
442array(1) {
443  [0]=>
444  int(10)
445}
446array(1) {
447  [0]=>
448  int(10)
449}
450array(1) {
451  [0]=>
452  int(10)
453}
454array(1) {
455  [0]=>
456  int(10)
457}
458array(1) {
459  [0]=>
460  int(10)
461}
462array(1) {
463  [0]=>
464  int(10)
465}
466array(1) {
467  [0]=>
468  int(10)
469}
470array(1) {
471  [0]=>
472  int(10)
473}
474bool(false)
475
476-- iteration 9 --
477array(1) {
478  [0]=>
479  int(10)
480}
481array(1) {
482  [0]=>
483  int(10)
484}
485array(1) {
486  [0]=>
487  int(10)
488}
489array(1) {
490  [0]=>
491  int(10)
492}
493array(1) {
494  [0]=>
495  int(10)
496}
497array(1) {
498  [0]=>
499  int(10)
500}
501array(1) {
502  [0]=>
503  int(10)
504}
505array(1) {
506  [0]=>
507  int(10)
508}
509array(1) {
510  [0]=>
511  int(10)
512}
513array(1) {
514  [0]=>
515  int(10)
516}
517array(1) {
518  [0]=>
519  int(10)
520}
521array(1) {
522  [0]=>
523  int(10)
524}
525bool(false)
526
527-- iteration 10 --
528array(1) {
529  [0]=>
530  int(10)
531}
532array(1) {
533  [0]=>
534  int(10)
535}
536array(1) {
537  [0]=>
538  int(10)
539}
540array(1) {
541  [0]=>
542  int(10)
543}
544array(1) {
545  [0]=>
546  int(10)
547}
548array(1) {
549  [0]=>
550  int(10)
551}
552array(1) {
553  [0]=>
554  int(10)
555}
556array(1) {
557  [0]=>
558  int(10)
559}
560array(1) {
561  [0]=>
562  int(10)
563}
564array(1) {
565  [0]=>
566  int(10)
567}
568array(1) {
569  [0]=>
570  int(10)
571}
572array(1) {
573  [0]=>
574  int(10)
575}
576bool(false)
577
578-- iteration 11 --
579array(1) {
580  [0]=>
581  int(10)
582}
583array(1) {
584  [0]=>
585  int(10)
586}
587array(1) {
588  [0]=>
589  int(10)
590}
591array(1) {
592  [0]=>
593  int(10)
594}
595array(1) {
596  [0]=>
597  int(10)
598}
599array(1) {
600  [0]=>
601  int(10)
602}
603array(1) {
604  [0]=>
605  int(10)
606}
607array(1) {
608  [0]=>
609  int(10)
610}
611array(1) {
612  [0]=>
613  int(10)
614}
615array(1) {
616  [0]=>
617  int(10)
618}
619array(1) {
620  [0]=>
621  int(10)
622}
623array(1) {
624  [0]=>
625  int(10)
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
709