import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-strings / vfprintf_variation7.php
blob18e23e567a7e399a714e2c832f1f545342607d73
1 <?php
2 /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
3 * Description: Write a formatted string to a stream
4 * Source code: ext/standard/formatted_print.c
5 */
7 /*
8 * Test vfprintf() when different string formats and string values are passed to
9 * the '$format' and '$args' arguments of the function
12 echo "*** Testing vfprintf() : string formats with strings ***\n";
15 // defining different heredoc strings
16 $heredoc_string = <<<EOT
17 This is string defined
18 using heredoc.
19 EOT;
21 /* heredoc string with only numerics */
22 $heredoc_numeric_string = <<<EOT
23 123456 3993
24 4849 string
25 EOT;
27 /* empty heardoc string */
28 $heredoc_empty_string = <<<EOT
29 EOT;
31 // defining array of string formats
32 $formats = array(
33 "%s",
34 "%+s %-s %S",
35 "%ls %Ls, %4s %-4s",
36 "%10.4s %-10.4s %04s %04.4s",
37 "%'#2s %'2s %'$2s %'_2s",
38 "%% %%s %10 s%",
39 '%3$s %4$s %1$s %2$s'
42 // Arrays of string values for the format defined in $format.
43 // Each sub array contains string values which correspond to each format string in $format
44 $args_array = array(
45 array(" "),
46 array("hello\0world", "hello\0", "\0hello"),
47 array("@#$%&*", "@#$%&*", "\x55F", "\001"),
48 array("sunday", 'monday', "tuesday", 'wednesday'),
49 array($heredoc_string, "abcdef", $heredoc_numeric_string, $heredoc_empty_string),
50 array("one", "two", 'three', 'four'),
51 array("three", 'four', 'one', "two")
55 /* creating dumping file */
56 $data_file = dirname(__FILE__) . '/vfprintf_variation7.phpt.txt';
57 if (!($fp = fopen($data_file, 'wt')))
58 return;
60 // looping to test vfprintf() with different string formats from the above $format array
61 // and with string from the above $args_array array
62 $counter = 1;
63 foreach($formats as $format) {
64 fprintf($fp, "\n-- Iteration %d --\n",$counter);
65 vfprintf($fp, $format, $args_array[$counter-1]);
66 $counter++;
69 fclose($fp);
70 print_r(file_get_contents($data_file));
71 echo "\n";
73 unlink($data_file);
76 ===DONE===