2 /* Prototype : string vsprintf(string format, array args)
3 * Description: Return a formatted string
4 * Source code: ext/standard/formatted_print.c
8 * Test vsprintf() when different string formats and non-string values are passed to
9 * the '$format' and '$args' arguments of the function
12 error_reporting(E_ALL
& ~E_NOTICE
);
14 echo "*** Testing vsprintf() : string formats and non-string values ***\n";
16 // defining array of string formats
20 %10.4s %-10.4s %04s %04.4s
21 %\'#2s %\'2s %\'$2s %\'_2s
24 // Arrays of non string values for the format defined in $format.
25 // Each sub array contains non string values which correspond to each format in $format
28 // array of float values
30 123456.234, -1234.6789, +
1234.6789,
31 2.1234567e10
, +
2.7654321e10
, -2.7654321e10
, 2.1234567e10
,
32 12345.780, 12.000000011111, -12.00000111111, -123456.234,
33 3.33, +
4.44, 1.11,-2.22 ),
35 // array of int values
37 123456, -12346789, +
12346789,
38 123200, +
20000, -40000, 22212,
39 12345780, 1211111, -12111111, -12345634,
44 array( array(0), array(1, 2), array(-1, -1),
45 array("123"), array('-123'), array("-123"),
46 array(true), array(false), array(TRUE), array(FALSE),
47 array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
48 array("3"), array("4"), array("1"), array("2") ),
50 // array of boolean data
51 array( true, TRUE, false,
53 true, false, TRUE, FALSE,
59 // looping to test vsprintf() with different string formats from the above $format array
60 // and with non-string values from the above $args_array array
62 foreach($args_array as $args) {
63 echo "\n-- Iteration $counter --\n";
64 var_dump( vsprintf($formats, $args) );