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