1--TEST--
2Test sprintf() function : usage variations - string formats with float 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 float values ***\n";
11
12// array of float values
13$float_values = array(
14  -2147483649,
15  2147483648,
16  -0x80000001, // float value, beyond max negative int
17  0x800000001, // float value, beyond max positive int
18  020000000001, // float value, beyond max positive int
19  -020000000001, // float value, beyond max negative int
20  0.0,
21  -0.1,
22  1.0,
23  1e3,
24  -1e2,
25  1.23456E8,
26  -1.234567E9,
27  10.0000000000000000005,
28  10.123e+5
29);
30
31// array of string formats
32$string_formats = array(
33  "%s", "%hs", "%ls",
34  "%Ls"," %s", "%s ",
35  "\t%s", "\n%s", "%4s",
36  "%30s", "%[a-zA-Z0-9]", "%*s"
37);
38
39$count = 1;
40foreach($float_values as $float_value) {
41  echo "\n-- Iteration $count --\n";
42
43  foreach($string_formats as $format) {
44    var_dump( sprintf($format, $float_value) );
45  }
46  $count++;
47};
48
49echo "Done";
50?>
51--EXPECT--
52*** Testing sprintf() : string formats with float values ***
53
54-- Iteration 1 --
55string(11) "-2147483649"
56string(1) "s"
57string(11) "-2147483649"
58string(1) "s"
59string(12) " -2147483649"
60string(12) "-2147483649 "
61string(12) "	-2147483649"
62string(12) "
63-2147483649"
64string(11) "-2147483649"
65string(30) "                   -2147483649"
66string(10) "a-zA-Z0-9]"
67string(1) "s"
68
69-- Iteration 2 --
70string(10) "2147483648"
71string(1) "s"
72string(10) "2147483648"
73string(1) "s"
74string(11) " 2147483648"
75string(11) "2147483648 "
76string(11) "	2147483648"
77string(11) "
782147483648"
79string(10) "2147483648"
80string(30) "                    2147483648"
81string(10) "a-zA-Z0-9]"
82string(1) "s"
83
84-- Iteration 3 --
85string(11) "-2147483649"
86string(1) "s"
87string(11) "-2147483649"
88string(1) "s"
89string(12) " -2147483649"
90string(12) "-2147483649 "
91string(12) "	-2147483649"
92string(12) "
93-2147483649"
94string(11) "-2147483649"
95string(30) "                   -2147483649"
96string(10) "a-zA-Z0-9]"
97string(1) "s"
98
99-- Iteration 4 --
100string(11) "34359738369"
101string(1) "s"
102string(11) "34359738369"
103string(1) "s"
104string(12) " 34359738369"
105string(12) "34359738369 "
106string(12) "	34359738369"
107string(12) "
10834359738369"
109string(11) "34359738369"
110string(30) "                   34359738369"
111string(10) "a-zA-Z0-9]"
112string(1) "s"
113
114-- Iteration 5 --
115string(10) "2147483649"
116string(1) "s"
117string(10) "2147483649"
118string(1) "s"
119string(11) " 2147483649"
120string(11) "2147483649 "
121string(11) "	2147483649"
122string(11) "
1232147483649"
124string(10) "2147483649"
125string(30) "                    2147483649"
126string(10) "a-zA-Z0-9]"
127string(1) "s"
128
129-- Iteration 6 --
130string(11) "-2147483649"
131string(1) "s"
132string(11) "-2147483649"
133string(1) "s"
134string(12) " -2147483649"
135string(12) "-2147483649 "
136string(12) "	-2147483649"
137string(12) "
138-2147483649"
139string(11) "-2147483649"
140string(30) "                   -2147483649"
141string(10) "a-zA-Z0-9]"
142string(1) "s"
143
144-- Iteration 7 --
145string(1) "0"
146string(1) "s"
147string(1) "0"
148string(1) "s"
149string(2) " 0"
150string(2) "0 "
151string(2) "	0"
152string(2) "
1530"
154string(4) "   0"
155string(30) "                             0"
156string(10) "a-zA-Z0-9]"
157string(1) "s"
158
159-- Iteration 8 --
160string(4) "-0.1"
161string(1) "s"
162string(4) "-0.1"
163string(1) "s"
164string(5) " -0.1"
165string(5) "-0.1 "
166string(5) "	-0.1"
167string(5) "
168-0.1"
169string(4) "-0.1"
170string(30) "                          -0.1"
171string(10) "a-zA-Z0-9]"
172string(1) "s"
173
174-- Iteration 9 --
175string(1) "1"
176string(1) "s"
177string(1) "1"
178string(1) "s"
179string(2) " 1"
180string(2) "1 "
181string(2) "	1"
182string(2) "
1831"
184string(4) "   1"
185string(30) "                             1"
186string(10) "a-zA-Z0-9]"
187string(1) "s"
188
189-- Iteration 10 --
190string(4) "1000"
191string(1) "s"
192string(4) "1000"
193string(1) "s"
194string(5) " 1000"
195string(5) "1000 "
196string(5) "	1000"
197string(5) "
1981000"
199string(4) "1000"
200string(30) "                          1000"
201string(10) "a-zA-Z0-9]"
202string(1) "s"
203
204-- Iteration 11 --
205string(4) "-100"
206string(1) "s"
207string(4) "-100"
208string(1) "s"
209string(5) " -100"
210string(5) "-100 "
211string(5) "	-100"
212string(5) "
213-100"
214string(4) "-100"
215string(30) "                          -100"
216string(10) "a-zA-Z0-9]"
217string(1) "s"
218
219-- Iteration 12 --
220string(9) "123456000"
221string(1) "s"
222string(9) "123456000"
223string(1) "s"
224string(10) " 123456000"
225string(10) "123456000 "
226string(10) "	123456000"
227string(10) "
228123456000"
229string(9) "123456000"
230string(30) "                     123456000"
231string(10) "a-zA-Z0-9]"
232string(1) "s"
233
234-- Iteration 13 --
235string(11) "-1234567000"
236string(1) "s"
237string(11) "-1234567000"
238string(1) "s"
239string(12) " -1234567000"
240string(12) "-1234567000 "
241string(12) "	-1234567000"
242string(12) "
243-1234567000"
244string(11) "-1234567000"
245string(30) "                   -1234567000"
246string(10) "a-zA-Z0-9]"
247string(1) "s"
248
249-- Iteration 14 --
250string(2) "10"
251string(1) "s"
252string(2) "10"
253string(1) "s"
254string(3) " 10"
255string(3) "10 "
256string(3) "	10"
257string(3) "
25810"
259string(4) "  10"
260string(30) "                            10"
261string(10) "a-zA-Z0-9]"
262string(1) "s"
263
264-- Iteration 15 --
265string(7) "1012300"
266string(1) "s"
267string(7) "1012300"
268string(1) "s"
269string(8) " 1012300"
270string(8) "1012300 "
271string(8) "	1012300"
272string(8) "
2731012300"
274string(7) "1012300"
275string(30) "                       1012300"
276string(10) "a-zA-Z0-9]"
277string(1) "s"
278Done
279