1--TEST--
2Test fscanf() function: usage variations - float formats with arrays
3--FILE--
4<?php
5
6/* Test fscanf() to scan arrays using different float format types */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): different float format types with arrays ***\n";
11
12// create a file
13$filename = "$file_path/fscanf_variation11.tmp";
14$file_handle = fopen($filename, "w");
15if($file_handle == false)
16  exit("Error:failed to open file $filename");
17
18// array types
19$array_types = array (
20  array(),
21  array(0),
22  array(1),
23  array(NULL),
24  array(null),
25  array("string"),
26  array(true),
27  array(TRUE),
28  array(false),
29  array(FALSE),
30  array(1,2,3,4),
31  array(1 => "One", "two" => 2)
32);
33
34$float_formats = array( "%f",
35                        "%hf", "%lf", "%Lf",
36                        " %f", "%f ", "% f",
37                        "\t%f", "\n%f", "%4f",
38                        "%30f", "%[0-9]", "%*f"
39                 );
40
41$counter = 1;
42
43// writing to the file
44foreach($array_types as $value) {
45  @fprintf($file_handle, "%s", $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 float formats
59foreach($float_formats as $float_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    try {
65      var_dump(fscanf($file_handle,$float_format));
66    } catch (ValueError $exception) {
67      echo $exception->getMessage() . "\n";
68    }
69  }
70  $counter++;
71}
72
73echo "\n*** Done ***";
74?>
75--CLEAN--
76<?php
77$file_path = __DIR__;
78$filename = "$file_path/fscanf_variation11.tmp";
79unlink($filename);
80?>
81--EXPECT--
82*** Test fscanf(): different float format types with arrays ***
83
84-- iteration 1 --
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}
129array(1) {
130  [0]=>
131  NULL
132}
133bool(false)
134
135-- iteration 2 --
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}
180array(1) {
181  [0]=>
182  NULL
183}
184bool(false)
185
186-- iteration 3 --
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}
231array(1) {
232  [0]=>
233  NULL
234}
235bool(false)
236
237-- iteration 4 --
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}
282array(1) {
283  [0]=>
284  NULL
285}
286bool(false)
287
288-- iteration 5 --
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}
333array(1) {
334  [0]=>
335  NULL
336}
337bool(false)
338
339-- iteration 6 --
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}
384array(1) {
385  [0]=>
386  NULL
387}
388bool(false)
389
390-- iteration 7 --
391Bad scan conversion character " "
392Bad scan conversion character " "
393Bad scan conversion character " "
394Bad scan conversion character " "
395Bad scan conversion character " "
396Bad scan conversion character " "
397Bad scan conversion character " "
398Bad scan conversion character " "
399Bad scan conversion character " "
400Bad scan conversion character " "
401Bad scan conversion character " "
402Bad scan conversion character " "
403bool(false)
404
405-- iteration 8 --
406array(1) {
407  [0]=>
408  NULL
409}
410array(1) {
411  [0]=>
412  NULL
413}
414array(1) {
415  [0]=>
416  NULL
417}
418array(1) {
419  [0]=>
420  NULL
421}
422array(1) {
423  [0]=>
424  NULL
425}
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}
454bool(false)
455
456-- iteration 9 --
457array(1) {
458  [0]=>
459  NULL
460}
461array(1) {
462  [0]=>
463  NULL
464}
465array(1) {
466  [0]=>
467  NULL
468}
469array(1) {
470  [0]=>
471  NULL
472}
473array(1) {
474  [0]=>
475  NULL
476}
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}
505bool(false)
506
507-- iteration 10 --
508array(1) {
509  [0]=>
510  NULL
511}
512array(1) {
513  [0]=>
514  NULL
515}
516array(1) {
517  [0]=>
518  NULL
519}
520array(1) {
521  [0]=>
522  NULL
523}
524array(1) {
525  [0]=>
526  NULL
527}
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}
556bool(false)
557
558-- iteration 11 --
559array(1) {
560  [0]=>
561  NULL
562}
563array(1) {
564  [0]=>
565  NULL
566}
567array(1) {
568  [0]=>
569  NULL
570}
571array(1) {
572  [0]=>
573  NULL
574}
575array(1) {
576  [0]=>
577  NULL
578}
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}
607bool(false)
608
609-- iteration 12 --
610array(1) {
611  [0]=>
612  NULL
613}
614array(1) {
615  [0]=>
616  NULL
617}
618array(1) {
619  [0]=>
620  NULL
621}
622array(1) {
623  [0]=>
624  NULL
625}
626array(1) {
627  [0]=>
628  NULL
629}
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}
658bool(false)
659
660-- iteration 13 --
661array(0) {
662}
663array(0) {
664}
665array(0) {
666}
667array(0) {
668}
669array(0) {
670}
671array(0) {
672}
673array(0) {
674}
675array(0) {
676}
677array(0) {
678}
679array(0) {
680}
681array(0) {
682}
683array(0) {
684}
685bool(false)
686
687*** Done ***
688