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 = __DIR__; 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 = __DIR__; 63$filename = "$file_path/fscanf_variation51.tmp"; 64if(file_exists($filename)) { 65 unlink($filename); 66} 67?> 68--EXPECTF-- 69*** Test fscanf(): to read from a file opened in write only mode *** 70 71-- iteration 1 -- 72 73Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 74bool(false) 75 76Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 77bool(false) 78 79Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 80bool(false) 81 82Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 83bool(false) 84 85Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 86bool(false) 87 88Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 89bool(false) 90 91Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 92bool(false) 93 94-- iteration 2 -- 95 96Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 97bool(false) 98 99Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 100bool(false) 101 102Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 103bool(false) 104 105Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 106bool(false) 107 108Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 109bool(false) 110 111Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 112bool(false) 113 114Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 115bool(false) 116 117-- iteration 3 -- 118 119Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 120bool(false) 121 122Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 123bool(false) 124 125Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 126bool(false) 127 128Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 129bool(false) 130 131Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 132bool(false) 133 134Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 135bool(false) 136 137Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 138bool(false) 139 140-- iteration 4 -- 141 142Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 143bool(false) 144 145Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 146bool(false) 147 148Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 149bool(false) 150 151Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 152bool(false) 153 154Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 155bool(false) 156 157Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 158bool(false) 159 160Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 161bool(false) 162 163-- iteration 5 -- 164 165Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 166bool(false) 167 168Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 169bool(false) 170 171Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 172bool(false) 173 174Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 175bool(false) 176 177Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 178bool(false) 179 180Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 181bool(false) 182 183Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 184bool(false) 185 186-- iteration 6 -- 187 188Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 189bool(false) 190 191Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 192bool(false) 193 194Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 195bool(false) 196 197Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 198bool(false) 199 200Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 201bool(false) 202 203Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 204bool(false) 205 206Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 207bool(false) 208 209-- iteration 7 -- 210 211Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 212bool(false) 213 214Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 215bool(false) 216 217Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 218bool(false) 219 220Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 221bool(false) 222 223Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 224bool(false) 225 226Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 227bool(false) 228 229Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 230bool(false) 231 232-- iteration 8 -- 233 234Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 235bool(false) 236 237Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 238bool(false) 239 240Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 241bool(false) 242 243Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 244bool(false) 245 246Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 247bool(false) 248 249Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 250bool(false) 251 252Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 253bool(false) 254 255-- iteration 9 -- 256 257Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 258bool(false) 259 260Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 261bool(false) 262 263Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 264bool(false) 265 266Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 267bool(false) 268 269Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 270bool(false) 271 272Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 273bool(false) 274 275Notice: fscanf(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 276bool(false) 277 278*** Done *** 279