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