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
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
21 /* heredoc string with only numerics */
22 $heredoc_numeric_string = <<<EOT
27 /* empty heardoc string */
28 $heredoc_empty_string = <<<EOT
31 // defining array of string formats
36 "%10.4s %-10.4s %04s %04.4s",
37 "%'#2s %'2s %'$2s %'_2s",
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
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')))
60 // looping to test vfprintf() with different string formats from the above $format array
61 // and with string from the above $args_array array
63 foreach($formats as $format) {
64 fprintf($fp, "\n-- Iteration %d --\n",$counter);
65 vfprintf($fp, $format, $args_array[$counter-1]);
70 print_r(file_get_contents($data_file));