1--TEST--
2Test sprintf() function : usage variations - hexa formats with string 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() : hexa formats with string values ***\n";
11
12// array of string values
13$string_values = array(
14  "",
15  '',
16  "0",
17  '0',
18  "1",
19  '1',
20  "\x01",
21  '\x01',
22  "\01",
23  '\01',
24  'string',
25  "string",
26  "true",
27  "FALSE",
28  'false',
29  'TRUE',
30  "NULL",
31  'null'
32);
33
34// array of hexa formats
35$hexa_formats = array(
36  "%x", "%xx", "%lx",
37  "%Lx", " %x", "%x ",
38  "\t%x", "\n%x", "%4x",
39  "%30x", "%[0-9A-Fa-f]", "%*x"
40);
41
42$count = 1;
43foreach($string_values as $string_value) {
44  echo "\n-- Iteration $count --\n";
45
46  foreach($hexa_formats as $format) {
47    var_dump( sprintf($format, $string_value) );
48  }
49  $count++;
50};
51
52echo "Done";
53?>
54--EXPECTF--
55*** Testing sprintf() : hexa formats with string values ***
56
57-- Iteration 1 --
58string(1) "0"
59string(2) "0x"
60string(1) "0"
61string(1) "x"
62string(2) " 0"
63string(2) "0 "
64string(2) "	0"
65string(2) "
660"
67string(4) "   0"
68string(30) "                             0"
69string(10) "0-9A-Fa-f]"
70string(1) "x"
71
72-- Iteration 2 --
73string(1) "0"
74string(2) "0x"
75string(1) "0"
76string(1) "x"
77string(2) " 0"
78string(2) "0 "
79string(2) "	0"
80string(2) "
810"
82string(4) "   0"
83string(30) "                             0"
84string(10) "0-9A-Fa-f]"
85string(1) "x"
86
87-- Iteration 3 --
88string(1) "0"
89string(2) "0x"
90string(1) "0"
91string(1) "x"
92string(2) " 0"
93string(2) "0 "
94string(2) "	0"
95string(2) "
960"
97string(4) "   0"
98string(30) "                             0"
99string(10) "0-9A-Fa-f]"
100string(1) "x"
101
102-- Iteration 4 --
103string(1) "0"
104string(2) "0x"
105string(1) "0"
106string(1) "x"
107string(2) " 0"
108string(2) "0 "
109string(2) "	0"
110string(2) "
1110"
112string(4) "   0"
113string(30) "                             0"
114string(10) "0-9A-Fa-f]"
115string(1) "x"
116
117-- Iteration 5 --
118string(1) "1"
119string(2) "1x"
120string(1) "1"
121string(1) "x"
122string(2) " 1"
123string(2) "1 "
124string(2) "	1"
125string(2) "
1261"
127string(4) "   1"
128string(30) "                             1"
129string(10) "0-9A-Fa-f]"
130string(1) "x"
131
132-- Iteration 6 --
133string(1) "1"
134string(2) "1x"
135string(1) "1"
136string(1) "x"
137string(2) " 1"
138string(2) "1 "
139string(2) "	1"
140string(2) "
1411"
142string(4) "   1"
143string(30) "                             1"
144string(10) "0-9A-Fa-f]"
145string(1) "x"
146
147-- Iteration 7 --
148string(1) "0"
149string(2) "0x"
150string(1) "0"
151string(1) "x"
152string(2) " 0"
153string(2) "0 "
154string(2) "	0"
155string(2) "
1560"
157string(4) "   0"
158string(30) "                             0"
159string(10) "0-9A-Fa-f]"
160string(1) "x"
161
162-- Iteration 8 --
163string(1) "0"
164string(2) "0x"
165string(1) "0"
166string(1) "x"
167string(2) " 0"
168string(2) "0 "
169string(2) "	0"
170string(2) "
1710"
172string(4) "   0"
173string(30) "                             0"
174string(10) "0-9A-Fa-f]"
175string(1) "x"
176
177-- Iteration 9 --
178string(1) "0"
179string(2) "0x"
180string(1) "0"
181string(1) "x"
182string(2) " 0"
183string(2) "0 "
184string(2) "	0"
185string(2) "
1860"
187string(4) "   0"
188string(30) "                             0"
189string(10) "0-9A-Fa-f]"
190string(1) "x"
191
192-- Iteration 10 --
193string(1) "0"
194string(2) "0x"
195string(1) "0"
196string(1) "x"
197string(2) " 0"
198string(2) "0 "
199string(2) "	0"
200string(2) "
2010"
202string(4) "   0"
203string(30) "                             0"
204string(10) "0-9A-Fa-f]"
205string(1) "x"
206
207-- Iteration 11 --
208string(1) "0"
209string(2) "0x"
210string(1) "0"
211string(1) "x"
212string(2) " 0"
213string(2) "0 "
214string(2) "	0"
215string(2) "
2160"
217string(4) "   0"
218string(30) "                             0"
219string(10) "0-9A-Fa-f]"
220string(1) "x"
221
222-- Iteration 12 --
223string(1) "0"
224string(2) "0x"
225string(1) "0"
226string(1) "x"
227string(2) " 0"
228string(2) "0 "
229string(2) "	0"
230string(2) "
2310"
232string(4) "   0"
233string(30) "                             0"
234string(10) "0-9A-Fa-f]"
235string(1) "x"
236
237-- Iteration 13 --
238string(1) "0"
239string(2) "0x"
240string(1) "0"
241string(1) "x"
242string(2) " 0"
243string(2) "0 "
244string(2) "	0"
245string(2) "
2460"
247string(4) "   0"
248string(30) "                             0"
249string(10) "0-9A-Fa-f]"
250string(1) "x"
251
252-- Iteration 14 --
253string(1) "0"
254string(2) "0x"
255string(1) "0"
256string(1) "x"
257string(2) " 0"
258string(2) "0 "
259string(2) "	0"
260string(2) "
2610"
262string(4) "   0"
263string(30) "                             0"
264string(10) "0-9A-Fa-f]"
265string(1) "x"
266
267-- Iteration 15 --
268string(1) "0"
269string(2) "0x"
270string(1) "0"
271string(1) "x"
272string(2) " 0"
273string(2) "0 "
274string(2) "	0"
275string(2) "
2760"
277string(4) "   0"
278string(30) "                             0"
279string(10) "0-9A-Fa-f]"
280string(1) "x"
281
282-- Iteration 16 --
283string(1) "0"
284string(2) "0x"
285string(1) "0"
286string(1) "x"
287string(2) " 0"
288string(2) "0 "
289string(2) "	0"
290string(2) "
2910"
292string(4) "   0"
293string(30) "                             0"
294string(10) "0-9A-Fa-f]"
295string(1) "x"
296
297-- Iteration 17 --
298string(1) "0"
299string(2) "0x"
300string(1) "0"
301string(1) "x"
302string(2) " 0"
303string(2) "0 "
304string(2) "	0"
305string(2) "
3060"
307string(4) "   0"
308string(30) "                             0"
309string(10) "0-9A-Fa-f]"
310string(1) "x"
311
312-- Iteration 18 --
313string(1) "0"
314string(2) "0x"
315string(1) "0"
316string(1) "x"
317string(2) " 0"
318string(2) "0 "
319string(2) "	0"
320string(2) "
3210"
322string(4) "   0"
323string(30) "                             0"
324string(10) "0-9A-Fa-f]"
325string(1) "x"
326Done
327