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