Annotation of embedaddon/php/ext/standard/tests/strings/sprintf_variation21.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sprintf() function : usage variations - char formats with integer values
3: --FILE--
4: <?php
5: /* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6: * Description: Return a formatted string
7: * Source code: ext/standard/formatted_print.c
8: */
9:
10: echo "*** Testing sprintf() : char formats with integer values ***\n";
11:
12: // array of integer values
13: $integer_values = array(
14: 0,
15: 1,
16: -1,
17: -2147483648, // max negative integer value
18: -2147483647,
19: 2147483647, // max positive integer value
20: 2147483640,
21: 0x123B, // integer as hexadecimal
22: 0x12ab,
23: 0Xfff,
24: 0XFA,
25: -0x80000000, // max negative integer as hexadecimal
26: 0x7fffffff, // max postive integer as hexadecimal
27: 0x7FFFFFFF, // max postive integer as hexadecimal
28: 0123, // integer as octal
29: 01912, // should be quivalent to octal 1
30: -020000000000, // max negative integer as octal
31: 017777777777 // max positive integer as octal
32: );
33:
34: // array of char formats
35: $char_formats = array(
36: "%c", "%hc", "%lc",
37: "%Lc", " %c", "%c ",
38: "\t%c", "\n%c", "%4c",
39: "%30c", "%[a-bA-B@#$&]", "%*c"
40: );
41:
42: $count = 1;
43: foreach($integer_values as $integer_value) {
44: echo "\n-- Iteration $count --\n";
45:
46: foreach($char_formats as $format) {
47: var_dump( sprintf($format, $integer_value) );
48: }
49: $count++;
50: };
51:
52: echo "Done";
53: ?>
54: --EXPECTF--
55: *** Testing sprintf() : char formats with integer values ***
56:
57: -- Iteration 1 --
58: string(1) "