Annotation of embedaddon/php/ext/standard/tests/strings/vfprintf_variation9.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test vfprintf() function : usage variations - char formats with char values
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
! 6: * Description: Write a formatted string to a stream
! 7: * Source code: ext/standard/formatted_print.c
! 8: */
! 9:
! 10: /*
! 11: * Test vfprintf() for char formats with an array of chars passed to the function
! 12: */
! 13:
! 14: echo "*** Testing vfprintf() : char formats with char values ***\n";
! 15:
! 16:
! 17: // defining array of char formats
! 18: $formats = array(
! 19: "%c",
! 20: "%+c %-c %C",
! 21: "%lc %Lc, %4c %-4c",
! 22: "%10.4c %-10.4c %04c %04.4c",
! 23: "%'#2c %'2c %'$2c %'_2c",
! 24: "%c %c %c %c",
! 25: "% %%c c%",
! 26: '%3$c %4$c %1$c %2$c'
! 27: );
! 28:
! 29: // Arrays of char values for the format defined in $format.
! 30: // Each sub array contains char values which correspond to each format string in $format
! 31: $args_array = array(
! 32: array(0),
! 33: array('c', 67, 68),
! 34: array(' ', " ", -67, +67),
! 35: array(97, -97, 98, +98),
! 36: array(97, -97, 98, +98),
! 37: array(0x123b, 0xfAb, 0123, 01293),
! 38: array(38, -1234, 2345),
! 39: array(67, 68, 65, 66)
! 40:
! 41: );
! 42:
! 43: /* creating dumping file */
! 44: $data_file = dirname(__FILE__) . '/dump.txt';
! 45: if (!($fp = fopen($data_file, 'wt')))
! 46: return;
! 47:
! 48: // looping to test vfprintf() with different char formats from the above $format array
! 49: // and with char values from the above $args_array array
! 50: $counter = 1;
! 51: foreach($formats as $format) {
! 52: fprintf($fp, "\n-- Iteration %d --\n",$counter);
! 53: vfprintf($fp, $format, $args_array[$counter-1]);
! 54: $counter++;
! 55: }
! 56:
! 57: fclose($fp);
! 58: print_r(file_get_contents($data_file));
! 59: echo "\n";
! 60:
! 61: unlink($data_file);
! 62:
! 63: ?>
! 64: ===DONE===
! 65: --EXPECTF--
! 66: *** Testing vfprintf() : char formats with char values ***
! 67:
! 68: -- Iteration 1 --
! 69: