1--TEST--
2Test 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
10echo "*** 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 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 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;
43foreach($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
52echo "Done";
53?>
54--EXPECTF--
55*** Testing sprintf() : char formats with integer values ***
56
57-- Iteration 1 --
58string(1) "�"
59string(1) "c"
60string(1) "�"
61string(1) "c"
62string(2) " �"
63string(2) "� "
64string(2) "	�"
65string(2) "
66�"
67string(1) "�"
68string(1) "�"
69string(11) "a-bA-B@#$&]"
70string(1) "c"
71
72-- Iteration 2 --
73string(1) ""
74string(1) "c"
75string(1) ""
76string(1) "c"
77string(2) " "
78string(2) " "
79string(2) "	"
80string(2) "
81"
82string(1) ""
83string(1) ""
84string(11) "a-bA-B@#$&]"
85string(1) "c"
86
87-- Iteration 3 --
88string(1) "�"
89string(1) "c"
90string(1) "�"
91string(1) "c"
92string(2) " �"
93string(2) "� "
94string(2) "	�"
95string(2) "
96�"
97string(1) "�"
98string(1) "�"
99string(11) "a-bA-B@#$&]"
100string(1) "c"
101
102-- Iteration 4 --
103string(1) "�"
104string(1) "c"
105string(1) "�"
106string(1) "c"
107string(2) " �"
108string(2) "� "
109string(2) "	�"
110string(2) "
111�"
112string(1) "�"
113string(1) "�"
114string(11) "a-bA-B@#$&]"
115string(1) "c"
116
117-- Iteration 5 --
118string(1) ""
119string(1) "c"
120string(1) ""
121string(1) "c"
122string(2) " "
123string(2) " "
124string(2) "	"
125string(2) "
126"
127string(1) ""
128string(1) ""
129string(11) "a-bA-B@#$&]"
130string(1) "c"
131
132-- Iteration 6 --
133string(1) "�"
134string(1) "c"
135string(1) "�"
136string(1) "c"
137string(2) " �"
138string(2) "� "
139string(2) "	�"
140string(2) "
141�"
142string(1) "�"
143string(1) "�"
144string(11) "a-bA-B@#$&]"
145string(1) "c"
146
147-- Iteration 7 --
148string(1) "�"
149string(1) "c"
150string(1) "�"
151string(1) "c"
152string(2) " �"
153string(2) "� "
154string(2) "	�"
155string(2) "
156�"
157string(1) "�"
158string(1) "�"
159string(11) "a-bA-B@#$&]"
160string(1) "c"
161
162-- Iteration 8 --
163string(1) ";"
164string(1) "c"
165string(1) ";"
166string(1) "c"
167string(2) " ;"
168string(2) "; "
169string(2) "	;"
170string(2) "
171;"
172string(1) ";"
173string(1) ";"
174string(11) "a-bA-B@#$&]"
175string(1) "c"
176
177-- Iteration 9 --
178string(1) "�"
179string(1) "c"
180string(1) "�"
181string(1) "c"
182string(2) " �"
183string(2) "� "
184string(2) "	�"
185string(2) "
186�"
187string(1) "�"
188string(1) "�"
189string(11) "a-bA-B@#$&]"
190string(1) "c"
191
192-- Iteration 10 --
193string(1) "�"
194string(1) "c"
195string(1) "�"
196string(1) "c"
197string(2) " �"
198string(2) "� "
199string(2) "	�"
200string(2) "
201�"
202string(1) "�"
203string(1) "�"
204string(11) "a-bA-B@#$&]"
205string(1) "c"
206
207-- Iteration 11 --
208string(1) "�"
209string(1) "c"
210string(1) "�"
211string(1) "c"
212string(2) " �"
213string(2) "� "
214string(2) "	�"
215string(2) "
216�"
217string(1) "�"
218string(1) "�"
219string(11) "a-bA-B@#$&]"
220string(1) "c"
221
222-- Iteration 12 --
223string(1) "�"
224string(1) "c"
225string(1) "�"
226string(1) "c"
227string(2) " �"
228string(2) "� "
229string(2) "	�"
230string(2) "
231�"
232string(1) "�"
233string(1) "�"
234string(11) "a-bA-B@#$&]"
235string(1) "c"
236
237-- Iteration 13 --
238string(1) "�"
239string(1) "c"
240string(1) "�"
241string(1) "c"
242string(2) " �"
243string(2) "� "
244string(2) "	�"
245string(2) "
246�"
247string(1) "�"
248string(1) "�"
249string(11) "a-bA-B@#$&]"
250string(1) "c"
251
252-- Iteration 14 --
253string(1) "�"
254string(1) "c"
255string(1) "�"
256string(1) "c"
257string(2) " �"
258string(2) "� "
259string(2) "	�"
260string(2) "
261�"
262string(1) "�"
263string(1) "�"
264string(11) "a-bA-B@#$&]"
265string(1) "c"
266
267-- Iteration 15 --
268string(1) "S"
269string(1) "c"
270string(1) "S"
271string(1) "c"
272string(2) " S"
273string(2) "S "
274string(2) "	S"
275string(2) "
276S"
277string(1) "S"
278string(1) "S"
279string(11) "a-bA-B@#$&]"
280string(1) "c"
281
282-- Iteration 16 --
283string(1) ""
284string(1) "c"
285string(1) ""
286string(1) "c"
287string(2) " "
288string(2) " "
289string(2) "	"
290string(2) "
291"
292string(1) ""
293string(1) ""
294string(11) "a-bA-B@#$&]"
295string(1) "c"
296
297-- Iteration 17 --
298string(1) "�"
299string(1) "c"
300string(1) "�"
301string(1) "c"
302string(2) " �"
303string(2) "� "
304string(2) "	�"
305string(2) "
306�"
307string(1) "�"
308string(1) "�"
309string(11) "a-bA-B@#$&]"
310string(1) "c"
311
312-- Iteration 18 --
313string(1) "�"
314string(1) "c"
315string(1) "�"
316string(1) "c"
317string(2) " �"
318string(2) "� "
319string(2) "	�"
320string(2) "
321�"
322string(1) "�"
323string(1) "�"
324string(11) "a-bA-B@#$&]"
325string(1) "c"
326Done
327