2
Test fscanf() function: usage variations - float formats with integer values
5
if (PHP_INT_SIZE != 4) {
6
die("skip this test is for 32bit platform only");
13
Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
14
Description: Parses input from a file according to a format
17
/* Test fscanf() to scan integer values using different float format types */
19
$file_path = dirname(__FILE__);
21
echo "*** Test fscanf(): different float format types with integer values ***\n";
24
$filename = "$file_path/fscanf_variation9.tmp";
25
$file_handle = fopen($filename, "w");
26
if($file_handle == false)
27
exit("Error:failed to open file $filename");
29
// array of float type values
31
$integer_values = array (
35
-2147483648, // max negative integer value
37
2147483647, // max positive integer value
39
0x123B, // integer as hexadecimal
43
-0x80000000, // max negative integer as hexadecimal
44
0x7fffffff, // max postive integer as hexadecimal
45
0x7FFFFFFF, // max postive integer as hexadecimal
46
0123, // integer as octal
47
01912, // should be quivalent to octal 1
48
-020000000000, // max negative integer as octal
49
017777777777 // max positive integer as octal
52
$float_formats = array( "%f", "%hf", "%lf", "%Lf", " %f", "%f ", "% f", "\t%f", "\n%f", "%4f", "%30f", "%[0-9]", "%*f");
56
// writing to the file
57
foreach($integer_values as $value) {
58
@fprintf($file_handle, $value);
59
@fprintf($file_handle, "\n");
64
// opening the file for reading
65
$file_handle = fopen($filename, "r");
66
if($file_handle == false) {
67
exit("Error:failed to open file $filename");
71
// reading the values from file using different float formats
72
foreach($float_formats as $float_format) {
73
// rewind the file so that for every foreach iteration the file pointer starts from bof
75
echo "\n-- iteration $counter --\n";
76
while( !feof($file_handle) ) {
77
var_dump( fscanf($file_handle,$float_format) );
82
echo "\n*** Done ***";
86
$file_path = dirname(__FILE__);
87
$filename = "$file_path/fscanf_variation9.tmp";
91
*** Test fscanf(): different float format types with integer values ***
545
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
548
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
551
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
554
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
557
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
560
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
563
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
566
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
569
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
572
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
575
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
578
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
581
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
584
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
587
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
590
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
593
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
596
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
923
string(10) "2147483647"
927
string(10) "2147483640"
951
string(10) "2147483647"
955
string(10) "2147483647"
971
string(10) "2147483647"