2 Test fscanf() function: usage variations - unsigned formats with resource
7 Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
8 Description: Parses input from a file according to a format
11 /* Test fscanf() to scan resource type using different unsigned format types */
13 $file_path = dirname(__FILE__);
15 echo "*** Test fscanf(): different unsigned format types with resource ***\n";
18 $filename = "$file_path/fscanf_variation41.tmp";
19 $file_handle = fopen($filename, "w");
20 if($file_handle == false)
21 exit("Error:failed to open file $filename");
24 // resource type variable
25 $fp = fopen (__FILE__, "r");
26 $dfp = opendir ( dirname(__FILE__) );
28 // array of resource types
29 $resource_types = array (
34 $unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u");
38 // writing to the file
39 foreach($resource_types as $value) {
40 @fprintf($file_handle, $value);
41 @fprintf($file_handle, "\n");
46 // opening the file for reading
47 $file_handle = fopen($filename, "r");
48 if($file_handle == false) {
49 exit("Error:failed to open file $filename");
53 // reading the values from file using different unsigned formats
54 foreach($unsigned_formats as $unsigned_format) {
55 // rewind the file so that for every foreach iteration the file pointer starts from bof
57 echo "\n-- iteration $counter --\n";
58 while( !feof($file_handle) ) {
59 var_dump( fscanf($file_handle,$unsigned_format) );
64 // closing the resources
68 echo "\n*** Done ***";
72 $file_path = dirname(__FILE__);
73 $filename = "$file_path/fscanf_variation41.tmp";
77 *** Test fscanf(): different unsigned format types with resource ***
147 Warning: fscanf(): Bad scan conversion character " " in %s on line %d
150 Warning: fscanf(): Bad scan conversion character " " in %s on line %d