import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fscanf_variation19.php
blob63b53b36510eafd36024597a2528c5eb9971138f
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 boolean data using different string format types */
10 $file_path = dirname(__FILE__);
12 echo "*** Test fscanf(): different string format types with boolean data ***\n";
14 // create a file
15 $filename = "$file_path/fscanf_variation19.tmp";
16 $file_handle = fopen($filename, "w");
17 if($file_handle == false)
18 exit("Error:failed to open file $filename");
20 // array of boolean types
21 $bool_types = array (
22 true,
23 false,
24 TRUE,
25 FALSE,
28 $string_formats = array( "%s",
29 "%hs", "%ls", "%Ls",
30 " %s", "%s ", "% s",
31 "\t%s", "\n%s", "%4s",
32 "%30s", "%[a-zA-Z0-9]", "%*s");
34 $counter = 1;
36 // writing to the file
37 foreach($bool_types as $value) {
38 @fprintf($file_handle, $value);
39 @fprintf($file_handle, "\n");
41 // closing the file
42 fclose($file_handle);
44 // opening the file for reading
45 $file_handle = fopen($filename, "r");
46 if($file_handle == false) {
47 exit("Error:failed to open file $filename");
50 $counter = 1;
51 // reading the values from file using different string formats
52 foreach($string_formats as $string_format) {
53 // rewind the file so that for every foreach iteration the file pointer starts from bof
54 rewind($file_handle);
55 echo "\n-- iteration $counter --\n";
56 while( !feof($file_handle) ) {
57 var_dump( fscanf($file_handle,$string_format) );
59 $counter++;
62 echo "\n*** Done ***";
63 ?><?php
64 $file_path = dirname(__FILE__);
65 $filename = "$file_path/fscanf_variation19.tmp";
66 unlink($filename);