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