import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fscanf_variation39.php
blob47f2f925c230abb88fefea2bc32722358aa75df1
1 <?php
3 /*
4 Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
5 Description: Parses input from a file according to a format
6 */
8 /* Test fscanf() to scan different integer values using different unsigned int format types */
10 $file_path = dirname(__FILE__);
12 echo "*** Test fscanf(): different unsigned int format types with different integer values ***\n";
14 // create a file
15 $filename = "$file_path/fscanf_variation39.tmp";
16 $file_handle = fopen($filename, "w");
17 if($file_handle == false)
18 exit("Error:failed to open file $filename");
20 // different valid integer values
21 $valid_ints = array(
24 -1,
25 -2147483648, // max negative integer value
26 -2147483647,
27 2147483647, // max positive integer value
28 2147483640,
29 0x123B, // integer as hexadecimal
30 0x12ab,
31 0Xfff,
32 0XFA,
33 -0x80000000, // max negative integer as hexadecimal
34 0x7fffffff, // max postive integer as hexadecimal
35 0x7FFFFFFF, // max postive integer as hexadecimal
36 0123, // integer as octal
37 01912, // should be quivalent to octal 1
38 -020000000000, // max negative integer as octal
39 017777777777 // max positive integer as octal
41 // various unsigned int formats
42 $unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u");
44 $counter = 1;
46 // writing to the file
47 foreach($valid_ints as $int_value) {
48 @fprintf($file_handle, $int_value);
49 @fprintf($file_handle, "\n");
51 // closing the file
52 fclose($file_handle);
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");
60 $counter = 1;
61 // reading the values from file using different unsigned int formats
62 foreach($unsigned_formats as $unsigned_format) {
63 // rewind the file so that for every foreach iteration the file pointer starts from bof
64 rewind($file_handle);
65 echo "\n-- iteration $counter --\n";
66 while( !feof($file_handle) ) {
67 var_dump( fscanf($file_handle,$unsigned_format) );
69 $counter++;
72 echo "\n*** Done ***";
73 ?><?php
74 $file_path = dirname(__FILE__);
75 $filename = "$file_path/fscanf_variation39.tmp";
76 unlink($filename);