1--TEST--
2Test sprintf() function : usage variations - int formats with int 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() : integer formats with integer values ***\n";
11
12// different valid  integer values
13$valid_ints = 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// various integer formats
34$int_formats = array(
35  "%d", "%hd", "%ld",
36  "%Ld", " %d", "%d ",
37  "\t%d", "\n%d", "%4d",
38  "%30d", "%[0-9]", "%*d"
39);
40
41$count = 1;
42foreach($valid_ints as $int_value) {
43  echo "\n-- Iteration $count --\n";
44
45  foreach($int_formats as $format) {
46    var_dump( sprintf($format, $int_value) );
47  }
48  $count++;
49};
50
51echo "Done";
52?>
53--EXPECT--
54*** Testing sprintf() : integer formats with integer values ***
55
56-- Iteration 1 --
57string(1) "0"
58string(1) "d"
59string(1) "0"
60string(1) "d"
61string(2) " 0"
62string(2) "0 "
63string(2) "	0"
64string(2) "
650"
66string(4) "   0"
67string(30) "                             0"
68string(4) "0-9]"
69string(1) "d"
70
71-- Iteration 2 --
72string(1) "1"
73string(1) "d"
74string(1) "1"
75string(1) "d"
76string(2) " 1"
77string(2) "1 "
78string(2) "	1"
79string(2) "
801"
81string(4) "   1"
82string(30) "                             1"
83string(4) "0-9]"
84string(1) "d"
85
86-- Iteration 3 --
87string(2) "-1"
88string(1) "d"
89string(2) "-1"
90string(1) "d"
91string(3) " -1"
92string(3) "-1 "
93string(3) "	-1"
94string(3) "
95-1"
96string(4) "  -1"
97string(30) "                            -1"
98string(4) "0-9]"
99string(1) "d"
100
101-- Iteration 4 --
102string(11) "-2147483648"
103string(1) "d"
104string(11) "-2147483648"
105string(1) "d"
106string(12) " -2147483648"
107string(12) "-2147483648 "
108string(12) "	-2147483648"
109string(12) "
110-2147483648"
111string(11) "-2147483648"
112string(30) "                   -2147483648"
113string(4) "0-9]"
114string(1) "d"
115
116-- Iteration 5 --
117string(11) "-2147483647"
118string(1) "d"
119string(11) "-2147483647"
120string(1) "d"
121string(12) " -2147483647"
122string(12) "-2147483647 "
123string(12) "	-2147483647"
124string(12) "
125-2147483647"
126string(11) "-2147483647"
127string(30) "                   -2147483647"
128string(4) "0-9]"
129string(1) "d"
130
131-- Iteration 6 --
132string(10) "2147483647"
133string(1) "d"
134string(10) "2147483647"
135string(1) "d"
136string(11) " 2147483647"
137string(11) "2147483647 "
138string(11) "	2147483647"
139string(11) "
1402147483647"
141string(10) "2147483647"
142string(30) "                    2147483647"
143string(4) "0-9]"
144string(1) "d"
145
146-- Iteration 7 --
147string(10) "2147483640"
148string(1) "d"
149string(10) "2147483640"
150string(1) "d"
151string(11) " 2147483640"
152string(11) "2147483640 "
153string(11) "	2147483640"
154string(11) "
1552147483640"
156string(10) "2147483640"
157string(30) "                    2147483640"
158string(4) "0-9]"
159string(1) "d"
160
161-- Iteration 8 --
162string(4) "4667"
163string(1) "d"
164string(4) "4667"
165string(1) "d"
166string(5) " 4667"
167string(5) "4667 "
168string(5) "	4667"
169string(5) "
1704667"
171string(4) "4667"
172string(30) "                          4667"
173string(4) "0-9]"
174string(1) "d"
175
176-- Iteration 9 --
177string(4) "4779"
178string(1) "d"
179string(4) "4779"
180string(1) "d"
181string(5) " 4779"
182string(5) "4779 "
183string(5) "	4779"
184string(5) "
1854779"
186string(4) "4779"
187string(30) "                          4779"
188string(4) "0-9]"
189string(1) "d"
190
191-- Iteration 10 --
192string(4) "4095"
193string(1) "d"
194string(4) "4095"
195string(1) "d"
196string(5) " 4095"
197string(5) "4095 "
198string(5) "	4095"
199string(5) "
2004095"
201string(4) "4095"
202string(30) "                          4095"
203string(4) "0-9]"
204string(1) "d"
205
206-- Iteration 11 --
207string(3) "250"
208string(1) "d"
209string(3) "250"
210string(1) "d"
211string(4) " 250"
212string(4) "250 "
213string(4) "	250"
214string(4) "
215250"
216string(4) " 250"
217string(30) "                           250"
218string(4) "0-9]"
219string(1) "d"
220
221-- Iteration 12 --
222string(11) "-2147483648"
223string(1) "d"
224string(11) "-2147483648"
225string(1) "d"
226string(12) " -2147483648"
227string(12) "-2147483648 "
228string(12) "	-2147483648"
229string(12) "
230-2147483648"
231string(11) "-2147483648"
232string(30) "                   -2147483648"
233string(4) "0-9]"
234string(1) "d"
235
236-- Iteration 13 --
237string(10) "2147483647"
238string(1) "d"
239string(10) "2147483647"
240string(1) "d"
241string(11) " 2147483647"
242string(11) "2147483647 "
243string(11) "	2147483647"
244string(11) "
2452147483647"
246string(10) "2147483647"
247string(30) "                    2147483647"
248string(4) "0-9]"
249string(1) "d"
250
251-- Iteration 14 --
252string(10) "2147483647"
253string(1) "d"
254string(10) "2147483647"
255string(1) "d"
256string(11) " 2147483647"
257string(11) "2147483647 "
258string(11) "	2147483647"
259string(11) "
2602147483647"
261string(10) "2147483647"
262string(30) "                    2147483647"
263string(4) "0-9]"
264string(1) "d"
265
266-- Iteration 15 --
267string(2) "83"
268string(1) "d"
269string(2) "83"
270string(1) "d"
271string(3) " 83"
272string(3) "83 "
273string(3) "	83"
274string(3) "
27583"
276string(4) "  83"
277string(30) "                            83"
278string(4) "0-9]"
279string(1) "d"
280
281-- Iteration 16 --
282string(1) "1"
283string(1) "d"
284string(1) "1"
285string(1) "d"
286string(2) " 1"
287string(2) "1 "
288string(2) "	1"
289string(2) "
2901"
291string(4) "   1"
292string(30) "                             1"
293string(4) "0-9]"
294string(1) "d"
295
296-- Iteration 17 --
297string(11) "-2147483648"
298string(1) "d"
299string(11) "-2147483648"
300string(1) "d"
301string(12) " -2147483648"
302string(12) "-2147483648 "
303string(12) "	-2147483648"
304string(12) "
305-2147483648"
306string(11) "-2147483648"
307string(30) "                   -2147483648"
308string(4) "0-9]"
309string(1) "d"
310
311-- Iteration 18 --
312string(10) "2147483647"
313string(1) "d"
314string(10) "2147483647"
315string(1) "d"
316string(11) " 2147483647"
317string(11) "2147483647 "
318string(11) "	2147483647"
319string(11) "
3202147483647"
321string(10) "2147483647"
322string(30) "                    2147483647"
323string(4) "0-9]"
324string(1) "d"
325Done
326