import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fscanf_variation43.php
blob214c503a75250dab726752d2586f7c849268aa55
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 strings using different unsigned format types */
10 $file_path = dirname(__FILE__);
12 echo "*** Test fscanf(): different unsigned format types with strings ***\n";
14 // create a file
15 $filename = "$file_path/fscanf_variation43.tmp";
16 $file_handle = fopen($filename, "w");
17 if($file_handle == false)
18 exit("Error:failed to open file $filename");
20 // array of strings
21 $strings = array (
22 "",
23 '',
24 "0",
25 '0',
26 "1",
27 '1',
28 "\x01",
29 '\x01',
30 "\01",
31 '\01',
32 'string',
33 "string",
34 "true",
35 "FALSE",
36 'false',
37 'TRUE',
38 "NULL",
39 'null'
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($strings as $string) {
48 @fprintf($file_handle, $string);
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 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_variation43.tmp";
76 unlink($filename);