2
Test fscanf() function: usage variations - scientific formats with float values
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 float values using different scientific format types */
13
$file_path = dirname(__FILE__);
15
echo "*** Test fscanf(): different scientific format types with float values ***\n";
18
$filename = "$file_path/fscanf_variation46.tmp";
19
$file_handle = fopen($filename, "w");
20
if($file_handle == false)
21
exit("Error:failed to open file $filename");
23
// array of float type values
25
$float_values = array (
28
-0x80000001, // float value, beyond max negative int
29
0x800000001, // float value, beyond max positive int
30
020000000001, // float value, beyond max positive int
31
-020000000001, // float value, beyond max negative int
39
10.0000000000000000005,
43
$scientific_formats = array( "%e", "%he", "%le", "%Le", " %e", "%e ", "% e", "\t%e", "\n%e", "%4e", "%30e", "%[0-9]", "%*e");
47
// writing to the file
48
foreach($float_values as $value) {
49
@fprintf($file_handle, $value);
50
@fprintf($file_handle, "\n");
55
// opening the file for reading
56
$file_handle = fopen($filename, "r");
57
if($file_handle == false) {
58
exit("Error:failed to open file $filename");
62
// reading the values from file using different scientific formats
63
foreach($scientific_formats as $scientific_format) {
64
// rewind the file so that for every foreach iteration the file pointer starts from bof
66
echo "\n-- iteration $counter --\n";
67
while( !feof($file_handle) ) {
68
var_dump( fscanf($file_handle,$scientific_format) );
73
echo "\n*** Done ***";
77
$file_path = dirname(__FILE__);
78
$filename = "$file_path/fscanf_variation46.tmp";
82
*** Test fscanf(): different scientific format types with float values ***
464
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
467
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
470
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
473
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
476
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
479
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
482
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
485
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
488
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
491
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
494
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
497
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
500
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
503
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
506
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
769
string(10) "2147483648"
777
string(11) "34359738369"
781
string(10) "2147483649"
809
string(9) "100000000"