1--TEST--
2Test sprintf() function : usage variations - float formats with strings
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() : float formats with strings ***\n";
11
12// array of string type 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  "123.456abc",
33  "+123.456abc"
34);
35
36// various float formats
37$float_formats = array(
38  "%f", "%hf", "%lf",
39  "%Lf", " %f", "%f ",
40  "\t%f", "\n%f", "%4f",
41  "%30f", "%[0-9]", "%*f"
42);
43
44$count = 1;
45foreach($string_values as $string_value) {
46  echo "\n-- Iteration $count --\n";
47
48  foreach($float_formats as $format) {
49    var_dump( sprintf($format, $string_value) );
50  }
51  $count++;
52};
53
54echo "Done";
55?>
56--EXPECT--
57*** Testing sprintf() : float formats with strings ***
58
59-- Iteration 1 --
60string(8) "0.000000"
61string(1) "f"
62string(8) "0.000000"
63string(1) "f"
64string(9) " 0.000000"
65string(9) "0.000000 "
66string(9) "	0.000000"
67string(9) "
680.000000"
69string(8) "0.000000"
70string(30) "                      0.000000"
71string(4) "0-9]"
72string(1) "f"
73
74-- Iteration 2 --
75string(8) "0.000000"
76string(1) "f"
77string(8) "0.000000"
78string(1) "f"
79string(9) " 0.000000"
80string(9) "0.000000 "
81string(9) "	0.000000"
82string(9) "
830.000000"
84string(8) "0.000000"
85string(30) "                      0.000000"
86string(4) "0-9]"
87string(1) "f"
88
89-- Iteration 3 --
90string(8) "0.000000"
91string(1) "f"
92string(8) "0.000000"
93string(1) "f"
94string(9) " 0.000000"
95string(9) "0.000000 "
96string(9) "	0.000000"
97string(9) "
980.000000"
99string(8) "0.000000"
100string(30) "                      0.000000"
101string(4) "0-9]"
102string(1) "f"
103
104-- Iteration 4 --
105string(8) "0.000000"
106string(1) "f"
107string(8) "0.000000"
108string(1) "f"
109string(9) " 0.000000"
110string(9) "0.000000 "
111string(9) "	0.000000"
112string(9) "
1130.000000"
114string(8) "0.000000"
115string(30) "                      0.000000"
116string(4) "0-9]"
117string(1) "f"
118
119-- Iteration 5 --
120string(8) "1.000000"
121string(1) "f"
122string(8) "1.000000"
123string(1) "f"
124string(9) " 1.000000"
125string(9) "1.000000 "
126string(9) "	1.000000"
127string(9) "
1281.000000"
129string(8) "1.000000"
130string(30) "                      1.000000"
131string(4) "0-9]"
132string(1) "f"
133
134-- Iteration 6 --
135string(8) "1.000000"
136string(1) "f"
137string(8) "1.000000"
138string(1) "f"
139string(9) " 1.000000"
140string(9) "1.000000 "
141string(9) "	1.000000"
142string(9) "
1431.000000"
144string(8) "1.000000"
145string(30) "                      1.000000"
146string(4) "0-9]"
147string(1) "f"
148
149-- Iteration 7 --
150string(8) "0.000000"
151string(1) "f"
152string(8) "0.000000"
153string(1) "f"
154string(9) " 0.000000"
155string(9) "0.000000 "
156string(9) "	0.000000"
157string(9) "
1580.000000"
159string(8) "0.000000"
160string(30) "                      0.000000"
161string(4) "0-9]"
162string(1) "f"
163
164-- Iteration 8 --
165string(8) "0.000000"
166string(1) "f"
167string(8) "0.000000"
168string(1) "f"
169string(9) " 0.000000"
170string(9) "0.000000 "
171string(9) "	0.000000"
172string(9) "
1730.000000"
174string(8) "0.000000"
175string(30) "                      0.000000"
176string(4) "0-9]"
177string(1) "f"
178
179-- Iteration 9 --
180string(8) "0.000000"
181string(1) "f"
182string(8) "0.000000"
183string(1) "f"
184string(9) " 0.000000"
185string(9) "0.000000 "
186string(9) "	0.000000"
187string(9) "
1880.000000"
189string(8) "0.000000"
190string(30) "                      0.000000"
191string(4) "0-9]"
192string(1) "f"
193
194-- Iteration 10 --
195string(8) "0.000000"
196string(1) "f"
197string(8) "0.000000"
198string(1) "f"
199string(9) " 0.000000"
200string(9) "0.000000 "
201string(9) "	0.000000"
202string(9) "
2030.000000"
204string(8) "0.000000"
205string(30) "                      0.000000"
206string(4) "0-9]"
207string(1) "f"
208
209-- Iteration 11 --
210string(8) "0.000000"
211string(1) "f"
212string(8) "0.000000"
213string(1) "f"
214string(9) " 0.000000"
215string(9) "0.000000 "
216string(9) "	0.000000"
217string(9) "
2180.000000"
219string(8) "0.000000"
220string(30) "                      0.000000"
221string(4) "0-9]"
222string(1) "f"
223
224-- Iteration 12 --
225string(8) "0.000000"
226string(1) "f"
227string(8) "0.000000"
228string(1) "f"
229string(9) " 0.000000"
230string(9) "0.000000 "
231string(9) "	0.000000"
232string(9) "
2330.000000"
234string(8) "0.000000"
235string(30) "                      0.000000"
236string(4) "0-9]"
237string(1) "f"
238
239-- Iteration 13 --
240string(8) "0.000000"
241string(1) "f"
242string(8) "0.000000"
243string(1) "f"
244string(9) " 0.000000"
245string(9) "0.000000 "
246string(9) "	0.000000"
247string(9) "
2480.000000"
249string(8) "0.000000"
250string(30) "                      0.000000"
251string(4) "0-9]"
252string(1) "f"
253
254-- Iteration 14 --
255string(8) "0.000000"
256string(1) "f"
257string(8) "0.000000"
258string(1) "f"
259string(9) " 0.000000"
260string(9) "0.000000 "
261string(9) "	0.000000"
262string(9) "
2630.000000"
264string(8) "0.000000"
265string(30) "                      0.000000"
266string(4) "0-9]"
267string(1) "f"
268
269-- Iteration 15 --
270string(8) "0.000000"
271string(1) "f"
272string(8) "0.000000"
273string(1) "f"
274string(9) " 0.000000"
275string(9) "0.000000 "
276string(9) "	0.000000"
277string(9) "
2780.000000"
279string(8) "0.000000"
280string(30) "                      0.000000"
281string(4) "0-9]"
282string(1) "f"
283
284-- Iteration 16 --
285string(8) "0.000000"
286string(1) "f"
287string(8) "0.000000"
288string(1) "f"
289string(9) " 0.000000"
290string(9) "0.000000 "
291string(9) "	0.000000"
292string(9) "
2930.000000"
294string(8) "0.000000"
295string(30) "                      0.000000"
296string(4) "0-9]"
297string(1) "f"
298
299-- Iteration 17 --
300string(8) "0.000000"
301string(1) "f"
302string(8) "0.000000"
303string(1) "f"
304string(9) " 0.000000"
305string(9) "0.000000 "
306string(9) "	0.000000"
307string(9) "
3080.000000"
309string(8) "0.000000"
310string(30) "                      0.000000"
311string(4) "0-9]"
312string(1) "f"
313
314-- Iteration 18 --
315string(8) "0.000000"
316string(1) "f"
317string(8) "0.000000"
318string(1) "f"
319string(9) " 0.000000"
320string(9) "0.000000 "
321string(9) "	0.000000"
322string(9) "
3230.000000"
324string(8) "0.000000"
325string(30) "                      0.000000"
326string(4) "0-9]"
327string(1) "f"
328
329-- Iteration 19 --
330string(10) "123.456000"
331string(1) "f"
332string(10) "123.456000"
333string(1) "f"
334string(11) " 123.456000"
335string(11) "123.456000 "
336string(11) "	123.456000"
337string(11) "
338123.456000"
339string(10) "123.456000"
340string(30) "                    123.456000"
341string(4) "0-9]"
342string(1) "f"
343
344-- Iteration 20 --
345string(10) "123.456000"
346string(1) "f"
347string(10) "123.456000"
348string(1) "f"
349string(11) " 123.456000"
350string(11) "123.456000 "
351string(11) "	123.456000"
352string(11) "
353123.456000"
354string(10) "123.456000"
355string(30) "                    123.456000"
356string(4) "0-9]"
357string(1) "f"
358Done
359