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 boolean data using different string format types */
10 $file_path = dirname(__FILE__
);
12 echo "*** Test fscanf(): different string format types with boolean data ***\n";
15 $filename = "$file_path/fscanf_variation19.tmp";
16 $file_handle = fopen($filename, "w");
17 if($file_handle == false)
18 exit("Error:failed to open file $filename");
20 // array of boolean types
28 $string_formats = array( "%s",
31 "\t%s", "\n%s", "%4s",
32 "%30s", "%[a-zA-Z0-9]", "%*s");
36 // writing to the file
37 foreach($bool_types as $value) {
38 @fprintf
($file_handle, $value);
39 @fprintf
($file_handle, "\n");
44 // opening the file for reading
45 $file_handle = fopen($filename, "r");
46 if($file_handle == false) {
47 exit("Error:failed to open file $filename");
51 // reading the values from file using different string formats
52 foreach($string_formats as $string_format) {
53 // rewind the file so that for every foreach iteration the file pointer starts from bof
55 echo "\n-- iteration $counter --\n";
56 while( !feof($file_handle) ) {
57 var_dump( fscanf($file_handle,$string_format) );
62 echo "\n*** Done ***";
64 $file_path = dirname(__FILE__
);
65 $filename = "$file_path/fscanf_variation19.tmp";