4 Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
5 Description: Parses input from a file according to a format
8 /* Test fscanf() to scan strings using different unsigned format types */
10 $file_path = dirname(__FILE__
);
12 echo "*** Test fscanf(): different unsigned format types with strings ***\n";
15 $filename = "$file_path/fscanf_variation43.tmp";
16 $file_handle = fopen($filename, "w");
17 if($file_handle == false)
18 exit("Error:failed to open file $filename");
42 $unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u");
46 // writing to the file
47 foreach($strings as $string) {
48 @fprintf
($file_handle, $string);
49 @fprintf
($file_handle, "\n");
54 // opening the file for reading
55 $file_handle = fopen($filename, "r");
56 if($file_handle == false) {
57 exit("Error:failed to open file $filename");
61 // reading the values from file using different unsigned formats
62 foreach($unsigned_formats as $unsigned_format) {
63 // rewind the file so that for every foreach iteration the file pointer starts from bof
65 echo "\n-- iteration $counter --\n";
66 while( !feof($file_handle) ) {
67 var_dump( fscanf($file_handle,$unsigned_format) );
72 echo "\n*** Done ***";
74 $file_path = dirname(__FILE__
);
75 $filename = "$file_path/fscanf_variation43.tmp";