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