1--TEST--
2Test fscanf() function: usage variations - file opened in write only mode
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 a file for read when file is opened inwrite only mode */
12
13$file_path = dirname(__FILE__);
14
15echo "*** Test fscanf(): to read from a file opened in write only mode ***\n";
16
17// create a file
18$filename = "$file_path/fscanf_variation51.tmp";
19$file_handle = fopen($filename, "w");
20if($file_handle == false)
21  exit("Error:failed to open file $filename");
22//writing data to the file
23@fwrite($file_handle,"sample text\n");
24
25//closing the file
26fclose($file_handle);
27
28// various formats
29$formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
30
31$counter = 1;
32
33// various write only modes
34$modes = array("w", "wb", "wt",
35               "a", "ab", "at",
36               "x", "xb", "xt"
37         );
38
39$counter = 1;
40// reading the values from file using different integer formats
41foreach($modes as $mode) {
42
43  $file_handle = fopen($filename, $mode);
44  if($file_handle == false) {
45    exit("Error:failed to open file $filename");
46  }
47  echo "\n-- iteration $counter --\n";
48
49  foreach($formats as $format) {
50    var_dump( fscanf($file_handle,$format) );
51    rewind($file_handle);
52  }
53  $counter++;
54  fclose($file_handle);
55  unlink($filename);
56}
57
58echo "\n*** Done ***";
59?>
60--CLEAN--
61<?php
62$file_path = dirname(__FILE__);
63$filename = "$file_path/fscanf_variation51.tmp";
64if(file_exists($filename)) {
65  unlink($filename);
66}
67?>
68--EXPECT--
69*** Test fscanf(): to read from a file opened in write only mode ***
70
71-- iteration 1 --
72bool(false)
73bool(false)
74bool(false)
75bool(false)
76bool(false)
77bool(false)
78bool(false)
79
80-- iteration 2 --
81bool(false)
82bool(false)
83bool(false)
84bool(false)
85bool(false)
86bool(false)
87bool(false)
88
89-- iteration 3 --
90bool(false)
91bool(false)
92bool(false)
93bool(false)
94bool(false)
95bool(false)
96bool(false)
97
98-- iteration 4 --
99bool(false)
100bool(false)
101bool(false)
102bool(false)
103bool(false)
104bool(false)
105bool(false)
106
107-- iteration 5 --
108bool(false)
109bool(false)
110bool(false)
111bool(false)
112bool(false)
113bool(false)
114bool(false)
115
116-- iteration 6 --
117bool(false)
118bool(false)
119bool(false)
120bool(false)
121bool(false)
122bool(false)
123bool(false)
124
125-- iteration 7 --
126bool(false)
127bool(false)
128bool(false)
129bool(false)
130bool(false)
131bool(false)
132bool(false)
133
134-- iteration 8 --
135bool(false)
136bool(false)
137bool(false)
138bool(false)
139bool(false)
140bool(false)
141bool(false)
142
143-- iteration 9 --
144bool(false)
145bool(false)
146bool(false)
147bool(false)
148bool(false)
149bool(false)
150bool(false)
151
152*** Done ***
153