1--TEST--
2Test sprintf() function : usage variations - string 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
10echo "*** Testing sprintf() : string 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 positive integer as hexadecimal
27  0x7FFFFFFF,  // max positive integer as hexadecimal
28  0123,        // integer as octal
29  01,       // 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 string formats
35$string_formats = array(
36  "%s", "%hs", "%ls",
37  "%Ls"," %s", "%s ",
38  "\t%s", "\n%s", "%4s",
39  "%30s", "%[a-zA-Z0-9]", "%*s"
40);
41
42$count = 1;
43foreach($integer_values as $integer_value) {
44  echo "\n-- Iteration $count --\n";
45
46  foreach($string_formats as $format) {
47    var_dump( sprintf($format, $integer_value) );
48  }
49  $count++;
50};
51
52echo "Done";
53?>
54--EXPECTF--
55*** Testing sprintf() : string formats with integer values ***
56
57-- Iteration 1 --
58string(1) "0"
59string(1) "s"
60string(1) "0"
61string(1) "s"
62string(2) " 0"
63string(2) "0 "
64string(2) "	0"
65string(2) "
660"
67string(4) "   0"
68string(30) "                             0"
69string(10) "a-zA-Z0-9]"
70string(1) "s"
71
72-- Iteration 2 --
73string(1) "1"
74string(1) "s"
75string(1) "1"
76string(1) "s"
77string(2) " 1"
78string(2) "1 "
79string(2) "	1"
80string(2) "
811"
82string(4) "   1"
83string(30) "                             1"
84string(10) "a-zA-Z0-9]"
85string(1) "s"
86
87-- Iteration 3 --
88string(2) "-1"
89string(1) "s"
90string(2) "-1"
91string(1) "s"
92string(3) " -1"
93string(3) "-1 "
94string(3) "	-1"
95string(3) "
96-1"
97string(4) "  -1"
98string(30) "                            -1"
99string(10) "a-zA-Z0-9]"
100string(1) "s"
101
102-- Iteration 4 --
103string(11) "-2147483648"
104string(1) "s"
105string(11) "-2147483648"
106string(1) "s"
107string(12) " -2147483648"
108string(12) "-2147483648 "
109string(12) "	-2147483648"
110string(12) "
111-2147483648"
112string(11) "-2147483648"
113string(30) "                   -2147483648"
114string(10) "a-zA-Z0-9]"
115string(1) "s"
116
117-- Iteration 5 --
118string(11) "-2147483647"
119string(1) "s"
120string(11) "-2147483647"
121string(1) "s"
122string(12) " -2147483647"
123string(12) "-2147483647 "
124string(12) "	-2147483647"
125string(12) "
126-2147483647"
127string(11) "-2147483647"
128string(30) "                   -2147483647"
129string(10) "a-zA-Z0-9]"
130string(1) "s"
131
132-- Iteration 6 --
133string(10) "2147483647"
134string(1) "s"
135string(10) "2147483647"
136string(1) "s"
137string(11) " 2147483647"
138string(11) "2147483647 "
139string(11) "	2147483647"
140string(11) "
1412147483647"
142string(10) "2147483647"
143string(30) "                    2147483647"
144string(10) "a-zA-Z0-9]"
145string(1) "s"
146
147-- Iteration 7 --
148string(10) "2147483640"
149string(1) "s"
150string(10) "2147483640"
151string(1) "s"
152string(11) " 2147483640"
153string(11) "2147483640 "
154string(11) "	2147483640"
155string(11) "
1562147483640"
157string(10) "2147483640"
158string(30) "                    2147483640"
159string(10) "a-zA-Z0-9]"
160string(1) "s"
161
162-- Iteration 8 --
163string(4) "4667"
164string(1) "s"
165string(4) "4667"
166string(1) "s"
167string(5) " 4667"
168string(5) "4667 "
169string(5) "	4667"
170string(5) "
1714667"
172string(4) "4667"
173string(30) "                          4667"
174string(10) "a-zA-Z0-9]"
175string(1) "s"
176
177-- Iteration 9 --
178string(4) "4779"
179string(1) "s"
180string(4) "4779"
181string(1) "s"
182string(5) " 4779"
183string(5) "4779 "
184string(5) "	4779"
185string(5) "
1864779"
187string(4) "4779"
188string(30) "                          4779"
189string(10) "a-zA-Z0-9]"
190string(1) "s"
191
192-- Iteration 10 --
193string(4) "4095"
194string(1) "s"
195string(4) "4095"
196string(1) "s"
197string(5) " 4095"
198string(5) "4095 "
199string(5) "	4095"
200string(5) "
2014095"
202string(4) "4095"
203string(30) "                          4095"
204string(10) "a-zA-Z0-9]"
205string(1) "s"
206
207-- Iteration 11 --
208string(3) "250"
209string(1) "s"
210string(3) "250"
211string(1) "s"
212string(4) " 250"
213string(4) "250 "
214string(4) "	250"
215string(4) "
216250"
217string(4) " 250"
218string(30) "                           250"
219string(10) "a-zA-Z0-9]"
220string(1) "s"
221
222-- Iteration 12 --
223string(11) "-2147483648"
224string(1) "s"
225string(11) "-2147483648"
226string(1) "s"
227string(12) " -2147483648"
228string(12) "-2147483648 "
229string(12) "	-2147483648"
230string(12) "
231-2147483648"
232string(11) "-2147483648"
233string(30) "                   -2147483648"
234string(10) "a-zA-Z0-9]"
235string(1) "s"
236
237-- Iteration 13 --
238string(10) "2147483647"
239string(1) "s"
240string(10) "2147483647"
241string(1) "s"
242string(11) " 2147483647"
243string(11) "2147483647 "
244string(11) "	2147483647"
245string(11) "
2462147483647"
247string(10) "2147483647"
248string(30) "                    2147483647"
249string(10) "a-zA-Z0-9]"
250string(1) "s"
251
252-- Iteration 14 --
253string(10) "2147483647"
254string(1) "s"
255string(10) "2147483647"
256string(1) "s"
257string(11) " 2147483647"
258string(11) "2147483647 "
259string(11) "	2147483647"
260string(11) "
2612147483647"
262string(10) "2147483647"
263string(30) "                    2147483647"
264string(10) "a-zA-Z0-9]"
265string(1) "s"
266
267-- Iteration 15 --
268string(2) "83"
269string(1) "s"
270string(2) "83"
271string(1) "s"
272string(3) " 83"
273string(3) "83 "
274string(3) "	83"
275string(3) "
27683"
277string(4) "  83"
278string(30) "                            83"
279string(10) "a-zA-Z0-9]"
280string(1) "s"
281
282-- Iteration 16 --
283string(1) "1"
284string(1) "s"
285string(1) "1"
286string(1) "s"
287string(2) " 1"
288string(2) "1 "
289string(2) "	1"
290string(2) "
2911"
292string(4) "   1"
293string(30) "                             1"
294string(10) "a-zA-Z0-9]"
295string(1) "s"
296
297-- Iteration 17 --
298string(11) "-2147483648"
299string(1) "s"
300string(11) "-2147483648"
301string(1) "s"
302string(12) " -2147483648"
303string(12) "-2147483648 "
304string(12) "	-2147483648"
305string(12) "
306-2147483648"
307string(11) "-2147483648"
308string(30) "                   -2147483648"
309string(10) "a-zA-Z0-9]"
310string(1) "s"
311
312-- Iteration 18 --
313string(10) "2147483647"
314string(1) "s"
315string(10) "2147483647"
316string(1) "s"
317string(11) " 2147483647"
318string(11) "2147483647 "
319string(11) "	2147483647"
320string(11) "
3212147483647"
322string(10) "2147483647"
323string(30) "                    2147483647"
324string(10) "a-zA-Z0-9]"
325string(1) "s"
326Done
327