1--TEST--
2Test fscanf() function: usage variations - scientific formats with boolean
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 boolean data using different scientific format types */
12
13$file_path = dirname(__FILE__);
14
15echo "*** Test fscanf(): different scientific format types with boolean data ***\n";
16
17// create a file
18$filename = "$file_path/fscanf_variation50.tmp";
19$file_handle = fopen($filename, "w");
20if($file_handle == false)
21  exit("Error:failed to open file $filename");
22
23// array of boolean types
24$bool_types = array (
25  true,
26  false,
27  TRUE,
28  FALSE,
29);
30
31$scientific_formats = array( "%e", "%he", "%le", "%Le", " %e", "%e ", "% e", "\t%e", "\n%e", "%4e", "%30e", "%[0-9]", "%*e");
32
33$counter = 1;
34
35// writing to the file
36foreach($bool_types as $value) {
37  @fprintf($file_handle, $value);
38  @fprintf($file_handle, "\n");
39}
40// closing the file
41fclose($file_handle);
42
43// opening the file for reading
44$file_handle = fopen($filename, "r");
45if($file_handle == false) {
46  exit("Error:failed to open file $filename");
47}
48
49$counter = 1;
50// reading the values from file using different scientific formats
51foreach($scientific_formats as $scientific_format) {
52  // rewind the file so that for every foreach iteration the file pointer starts from bof
53  rewind($file_handle);
54  echo "\n-- iteration $counter --\n";
55  while( !feof($file_handle) ) {
56    var_dump( fscanf($file_handle,$scientific_format) );
57  }
58  $counter++;
59}
60
61echo "\n*** Done ***";
62?>
63--CLEAN--
64<?php
65$file_path = dirname(__FILE__);
66$filename = "$file_path/fscanf_variation50.tmp";
67unlink($filename);
68?>
69--EXPECTF--
70*** Test fscanf(): different scientific format types with boolean data ***
71
72-- iteration 1 --
73array(1) {
74  [0]=>
75  float(1)
76}
77NULL
78array(1) {
79  [0]=>
80  float(1)
81}
82NULL
83bool(false)
84
85-- iteration 2 --
86array(1) {
87  [0]=>
88  float(1)
89}
90NULL
91array(1) {
92  [0]=>
93  float(1)
94}
95NULL
96bool(false)
97
98-- iteration 3 --
99array(1) {
100  [0]=>
101  float(1)
102}
103NULL
104array(1) {
105  [0]=>
106  float(1)
107}
108NULL
109bool(false)
110
111-- iteration 4 --
112array(1) {
113  [0]=>
114  float(1)
115}
116NULL
117array(1) {
118  [0]=>
119  float(1)
120}
121NULL
122bool(false)
123
124-- iteration 5 --
125array(1) {
126  [0]=>
127  float(1)
128}
129NULL
130array(1) {
131  [0]=>
132  float(1)
133}
134NULL
135bool(false)
136
137-- iteration 6 --
138array(1) {
139  [0]=>
140  float(1)
141}
142NULL
143array(1) {
144  [0]=>
145  float(1)
146}
147NULL
148bool(false)
149
150-- iteration 7 --
151
152Warning: fscanf(): Bad scan conversion character " " in %s on line %d
153NULL
154
155Warning: fscanf(): Bad scan conversion character " " in %s on line %d
156NULL
157
158Warning: fscanf(): Bad scan conversion character " " in %s on line %d
159NULL
160
161Warning: fscanf(): Bad scan conversion character " " in %s on line %d
162NULL
163bool(false)
164
165-- iteration 8 --
166array(1) {
167  [0]=>
168  float(1)
169}
170NULL
171array(1) {
172  [0]=>
173  float(1)
174}
175NULL
176bool(false)
177
178-- iteration 9 --
179array(1) {
180  [0]=>
181  float(1)
182}
183NULL
184array(1) {
185  [0]=>
186  float(1)
187}
188NULL
189bool(false)
190
191-- iteration 10 --
192array(1) {
193  [0]=>
194  float(1)
195}
196NULL
197array(1) {
198  [0]=>
199  float(1)
200}
201NULL
202bool(false)
203
204-- iteration 11 --
205array(1) {
206  [0]=>
207  float(1)
208}
209NULL
210array(1) {
211  [0]=>
212  float(1)
213}
214NULL
215bool(false)
216
217-- iteration 12 --
218array(1) {
219  [0]=>
220  string(1) "1"
221}
222array(1) {
223  [0]=>
224  NULL
225}
226array(1) {
227  [0]=>
228  string(1) "1"
229}
230array(1) {
231  [0]=>
232  NULL
233}
234bool(false)
235
236-- iteration 13 --
237array(0) {
238}
239NULL
240array(0) {
241}
242NULL
243bool(false)
244
245*** Done ***
246
247