2 Test fscanf() function: usage variations - float 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 float format types */
15 echo "*** Test fscanf(): different float format types with resource ***\n";
18 $filename = "$file_path/fscanf_variation10.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 ( __DIR__ );
28 // array of resource types
29 $resource_types = array (
34 $float_formats = array( "%f",
37 "\t%f", "\n%f", "%4f",
38 "%30f", "%[0-9]", "%*f"
43 // writing to the file
44 foreach($resource_types as $value) {
45 @fprintf($file_handle, "%s", $value);
46 @fprintf($file_handle, "\n");
51 // opening the file for reading
52 $file_handle = fopen($filename, "r");
53 if($file_handle == false) {
54 exit("Error:failed to open file $filename");
58 // reading the values from file using different formats formats
59 foreach($float_formats as $float_format) {
60 // rewind the file so that for every foreach iteration the file pointer starts from bof
62 echo "\n-- iteration $counter --\n";
63 while( !feof($file_handle) ) {
65 var_dump( fscanf($file_handle,$float_format) );
66 } catch (ValueError $exception) {
67 echo $exception->getMessage() . "\n";
73 // closing the resources
77 echo "\n*** Done ***";
82 $filename = "$file_path/fscanf_variation10.tmp";
86 *** Test fscanf(): different float format types with resource ***
155 Bad scan conversion character " "
156 Bad scan conversion character " "