1--TEST--
2Test fscanf() function: usage variations - octal formats with float values
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 float values using different octal format types */
12
13$file_path = dirname(__FILE__);
14
15echo "*** Test fscanf(): different octal format types with float values ***\n";
16
17// create a file
18$filename = "$file_path/fscanf_variation28.tmp";
19$file_handle = fopen($filename, "w");
20if($file_handle == false)
21  exit("Error:failed to open file $filename");
22
23// array of float type values
24
25$float_values = array (
26  -2147483649,
27  2147483648,
28  -0x80000001, // float value, beyond max negative int
29  0x800000001, // float value, beyond max positive int
30  020000000001, // float value, beyond max positive int
31  -020000000001, // float value, beyond max negative int
32  0.0,
33  -0.1,
34  1.0,
35  1e5,
36  -1e6,
37  1E8,
38  -1E9,
39  10.0000000000000000005,
40  10.5e+5
41);
42
43$octal_formats = array( "%o",
44                        "%ho", "%lo", "%Lo",
45                        " %o", "%o ", "% o",
46                        "\t%o", "\n%o", "%4o",
47                        "%30o", "%[0-7]", "%*o"
48                 );
49
50$counter = 1;
51
52// writing to the file
53foreach($float_values as $value) {
54  @fprintf($file_handle, $value);
55  @fprintf($file_handle, "\n");
56}
57// closing the file
58fclose($file_handle);
59
60// opening the file for reading
61$file_handle = fopen($filename, "r");
62if($file_handle == false) {
63  exit("Error:failed to open file $filename");
64}
65
66$counter = 1;
67// reading the values from file using different octal formats
68foreach($octal_formats as $octal_format) {
69  // rewind the file so that for every foreach iteration the file pointer starts from bof
70  rewind($file_handle);
71  echo "\n-- iteration $counter --\n";
72  while( !feof($file_handle) ) {
73    var_dump( fscanf($file_handle,$octal_format) );
74  }
75  $counter++;
76}
77
78echo "\n*** Done ***";
79?>
80--CLEAN--
81<?php
82$file_path = dirname(__FILE__);
83$filename = "$file_path/fscanf_variation28.tmp";
84unlink($filename);
85?>
86--EXPECTF--
87*** Test fscanf(): different octal format types with float values ***
88
89-- iteration 1 --
90array(1) {
91  [0]=>
92  int(-9020)
93}
94array(1) {
95  [0]=>
96  int(9020)
97}
98array(1) {
99  [0]=>
100  int(-9020)
101}
102array(1) {
103  [0]=>
104  int(1821)
105}
106array(1) {
107  [0]=>
108  int(9020)
109}
110array(1) {
111  [0]=>
112  int(-9020)
113}
114array(1) {
115  [0]=>
116  int(0)
117}
118array(1) {
119  [0]=>
120  int(0)
121}
122array(1) {
123  [0]=>
124  int(1)
125}
126array(1) {
127  [0]=>
128  int(32768)
129}
130array(1) {
131  [0]=>
132  int(-262144)
133}
134array(1) {
135  [0]=>
136  int(16777216)
137}
138array(1) {
139  [0]=>
140  int(-134217728)
141}
142array(1) {
143  [0]=>
144  int(8)
145}
146array(1) {
147  [0]=>
148  int(282624)
149}
150bool(false)
151
152-- iteration 2 --
153array(1) {
154  [0]=>
155  int(-9020)
156}
157array(1) {
158  [0]=>
159  int(9020)
160}
161array(1) {
162  [0]=>
163  int(-9020)
164}
165array(1) {
166  [0]=>
167  int(1821)
168}
169array(1) {
170  [0]=>
171  int(9020)
172}
173array(1) {
174  [0]=>
175  int(-9020)
176}
177array(1) {
178  [0]=>
179  int(0)
180}
181array(1) {
182  [0]=>
183  int(0)
184}
185array(1) {
186  [0]=>
187  int(1)
188}
189array(1) {
190  [0]=>
191  int(32768)
192}
193array(1) {
194  [0]=>
195  int(-262144)
196}
197array(1) {
198  [0]=>
199  int(16777216)
200}
201array(1) {
202  [0]=>
203  int(-134217728)
204}
205array(1) {
206  [0]=>
207  int(8)
208}
209array(1) {
210  [0]=>
211  int(282624)
212}
213bool(false)
214
215-- iteration 3 --
216array(1) {
217  [0]=>
218  int(-9020)
219}
220array(1) {
221  [0]=>
222  int(9020)
223}
224array(1) {
225  [0]=>
226  int(-9020)
227}
228array(1) {
229  [0]=>
230  int(1821)
231}
232array(1) {
233  [0]=>
234  int(9020)
235}
236array(1) {
237  [0]=>
238  int(-9020)
239}
240array(1) {
241  [0]=>
242  int(0)
243}
244array(1) {
245  [0]=>
246  int(0)
247}
248array(1) {
249  [0]=>
250  int(1)
251}
252array(1) {
253  [0]=>
254  int(32768)
255}
256array(1) {
257  [0]=>
258  int(-262144)
259}
260array(1) {
261  [0]=>
262  int(16777216)
263}
264array(1) {
265  [0]=>
266  int(-134217728)
267}
268array(1) {
269  [0]=>
270  int(8)
271}
272array(1) {
273  [0]=>
274  int(282624)
275}
276bool(false)
277
278-- iteration 4 --
279array(1) {
280  [0]=>
281  int(-9020)
282}
283array(1) {
284  [0]=>
285  int(9020)
286}
287array(1) {
288  [0]=>
289  int(-9020)
290}
291array(1) {
292  [0]=>
293  int(1821)
294}
295array(1) {
296  [0]=>
297  int(9020)
298}
299array(1) {
300  [0]=>
301  int(-9020)
302}
303array(1) {
304  [0]=>
305  int(0)
306}
307array(1) {
308  [0]=>
309  int(0)
310}
311array(1) {
312  [0]=>
313  int(1)
314}
315array(1) {
316  [0]=>
317  int(32768)
318}
319array(1) {
320  [0]=>
321  int(-262144)
322}
323array(1) {
324  [0]=>
325  int(16777216)
326}
327array(1) {
328  [0]=>
329  int(-134217728)
330}
331array(1) {
332  [0]=>
333  int(8)
334}
335array(1) {
336  [0]=>
337  int(282624)
338}
339bool(false)
340
341-- iteration 5 --
342array(1) {
343  [0]=>
344  int(-9020)
345}
346array(1) {
347  [0]=>
348  int(9020)
349}
350array(1) {
351  [0]=>
352  int(-9020)
353}
354array(1) {
355  [0]=>
356  int(1821)
357}
358array(1) {
359  [0]=>
360  int(9020)
361}
362array(1) {
363  [0]=>
364  int(-9020)
365}
366array(1) {
367  [0]=>
368  int(0)
369}
370array(1) {
371  [0]=>
372  int(0)
373}
374array(1) {
375  [0]=>
376  int(1)
377}
378array(1) {
379  [0]=>
380  int(32768)
381}
382array(1) {
383  [0]=>
384  int(-262144)
385}
386array(1) {
387  [0]=>
388  int(16777216)
389}
390array(1) {
391  [0]=>
392  int(-134217728)
393}
394array(1) {
395  [0]=>
396  int(8)
397}
398array(1) {
399  [0]=>
400  int(282624)
401}
402bool(false)
403
404-- iteration 6 --
405array(1) {
406  [0]=>
407  int(-9020)
408}
409array(1) {
410  [0]=>
411  int(9020)
412}
413array(1) {
414  [0]=>
415  int(-9020)
416}
417array(1) {
418  [0]=>
419  int(1821)
420}
421array(1) {
422  [0]=>
423  int(9020)
424}
425array(1) {
426  [0]=>
427  int(-9020)
428}
429array(1) {
430  [0]=>
431  int(0)
432}
433array(1) {
434  [0]=>
435  int(0)
436}
437array(1) {
438  [0]=>
439  int(1)
440}
441array(1) {
442  [0]=>
443  int(32768)
444}
445array(1) {
446  [0]=>
447  int(-262144)
448}
449array(1) {
450  [0]=>
451  int(16777216)
452}
453array(1) {
454  [0]=>
455  int(-134217728)
456}
457array(1) {
458  [0]=>
459  int(8)
460}
461array(1) {
462  [0]=>
463  int(282624)
464}
465bool(false)
466
467-- iteration 7 --
468
469Warning: fscanf(): Bad scan conversion character " " in %s on line %d
470NULL
471
472Warning: fscanf(): Bad scan conversion character " " in %s on line %d
473NULL
474
475Warning: fscanf(): Bad scan conversion character " " in %s on line %d
476NULL
477
478Warning: fscanf(): Bad scan conversion character " " in %s on line %d
479NULL
480
481Warning: fscanf(): Bad scan conversion character " " in %s on line %d
482NULL
483
484Warning: fscanf(): Bad scan conversion character " " in %s on line %d
485NULL
486
487Warning: fscanf(): Bad scan conversion character " " in %s on line %d
488NULL
489
490Warning: fscanf(): Bad scan conversion character " " in %s on line %d
491NULL
492
493Warning: fscanf(): Bad scan conversion character " " in %s on line %d
494NULL
495
496Warning: fscanf(): Bad scan conversion character " " in %s on line %d
497NULL
498
499Warning: fscanf(): Bad scan conversion character " " in %s on line %d
500NULL
501
502Warning: fscanf(): Bad scan conversion character " " in %s on line %d
503NULL
504
505Warning: fscanf(): Bad scan conversion character " " in %s on line %d
506NULL
507
508Warning: fscanf(): Bad scan conversion character " " in %s on line %d
509NULL
510
511Warning: fscanf(): Bad scan conversion character " " in %s on line %d
512NULL
513bool(false)
514
515-- iteration 8 --
516array(1) {
517  [0]=>
518  int(-9020)
519}
520array(1) {
521  [0]=>
522  int(9020)
523}
524array(1) {
525  [0]=>
526  int(-9020)
527}
528array(1) {
529  [0]=>
530  int(1821)
531}
532array(1) {
533  [0]=>
534  int(9020)
535}
536array(1) {
537  [0]=>
538  int(-9020)
539}
540array(1) {
541  [0]=>
542  int(0)
543}
544array(1) {
545  [0]=>
546  int(0)
547}
548array(1) {
549  [0]=>
550  int(1)
551}
552array(1) {
553  [0]=>
554  int(32768)
555}
556array(1) {
557  [0]=>
558  int(-262144)
559}
560array(1) {
561  [0]=>
562  int(16777216)
563}
564array(1) {
565  [0]=>
566  int(-134217728)
567}
568array(1) {
569  [0]=>
570  int(8)
571}
572array(1) {
573  [0]=>
574  int(282624)
575}
576bool(false)
577
578-- iteration 9 --
579array(1) {
580  [0]=>
581  int(-9020)
582}
583array(1) {
584  [0]=>
585  int(9020)
586}
587array(1) {
588  [0]=>
589  int(-9020)
590}
591array(1) {
592  [0]=>
593  int(1821)
594}
595array(1) {
596  [0]=>
597  int(9020)
598}
599array(1) {
600  [0]=>
601  int(-9020)
602}
603array(1) {
604  [0]=>
605  int(0)
606}
607array(1) {
608  [0]=>
609  int(0)
610}
611array(1) {
612  [0]=>
613  int(1)
614}
615array(1) {
616  [0]=>
617  int(32768)
618}
619array(1) {
620  [0]=>
621  int(-262144)
622}
623array(1) {
624  [0]=>
625  int(16777216)
626}
627array(1) {
628  [0]=>
629  int(-134217728)
630}
631array(1) {
632  [0]=>
633  int(8)
634}
635array(1) {
636  [0]=>
637  int(282624)
638}
639bool(false)
640
641-- iteration 10 --
642array(1) {
643  [0]=>
644  int(-140)
645}
646array(1) {
647  [0]=>
648  int(1127)
649}
650array(1) {
651  [0]=>
652  int(-140)
653}
654array(1) {
655  [0]=>
656  int(1821)
657}
658array(1) {
659  [0]=>
660  int(1127)
661}
662array(1) {
663  [0]=>
664  int(-140)
665}
666array(1) {
667  [0]=>
668  int(0)
669}
670array(1) {
671  [0]=>
672  int(0)
673}
674array(1) {
675  [0]=>
676  int(1)
677}
678array(1) {
679  [0]=>
680  int(512)
681}
682array(1) {
683  [0]=>
684  int(-64)
685}
686array(1) {
687  [0]=>
688  int(512)
689}
690array(1) {
691  [0]=>
692  int(-64)
693}
694array(1) {
695  [0]=>
696  int(8)
697}
698array(1) {
699  [0]=>
700  int(552)
701}
702bool(false)
703
704-- iteration 11 --
705array(1) {
706  [0]=>
707  int(-9020)
708}
709array(1) {
710  [0]=>
711  int(9020)
712}
713array(1) {
714  [0]=>
715  int(-9020)
716}
717array(1) {
718  [0]=>
719  int(1821)
720}
721array(1) {
722  [0]=>
723  int(9020)
724}
725array(1) {
726  [0]=>
727  int(-9020)
728}
729array(1) {
730  [0]=>
731  int(0)
732}
733array(1) {
734  [0]=>
735  int(0)
736}
737array(1) {
738  [0]=>
739  int(1)
740}
741array(1) {
742  [0]=>
743  int(32768)
744}
745array(1) {
746  [0]=>
747  int(-262144)
748}
749array(1) {
750  [0]=>
751  int(16777216)
752}
753array(1) {
754  [0]=>
755  int(-134217728)
756}
757array(1) {
758  [0]=>
759  int(8)
760}
761array(1) {
762  [0]=>
763  int(282624)
764}
765bool(false)
766
767-- iteration 12 --
768array(1) {
769  [0]=>
770  NULL
771}
772array(1) {
773  [0]=>
774  string(5) "21474"
775}
776array(1) {
777  [0]=>
778  NULL
779}
780array(1) {
781  [0]=>
782  string(4) "3435"
783}
784array(1) {
785  [0]=>
786  string(5) "21474"
787}
788array(1) {
789  [0]=>
790  NULL
791}
792array(1) {
793  [0]=>
794  string(1) "0"
795}
796array(1) {
797  [0]=>
798  NULL
799}
800array(1) {
801  [0]=>
802  string(1) "1"
803}
804array(1) {
805  [0]=>
806  string(6) "100000"
807}
808array(1) {
809  [0]=>
810  NULL
811}
812array(1) {
813  [0]=>
814  string(9) "100000000"
815}
816array(1) {
817  [0]=>
818  NULL
819}
820array(1) {
821  [0]=>
822  string(2) "10"
823}
824array(1) {
825  [0]=>
826  string(7) "1050000"
827}
828bool(false)
829
830-- iteration 13 --
831array(0) {
832}
833array(0) {
834}
835array(0) {
836}
837array(0) {
838}
839array(0) {
840}
841array(0) {
842}
843array(0) {
844}
845array(0) {
846}
847array(0) {
848}
849array(0) {
850}
851array(0) {
852}
853array(0) {
854}
855array(0) {
856}
857array(0) {
858}
859array(0) {
860}
861bool(false)
862
863*** Done ***
864