1--TEST--
2Test sprintf() function : usage variations - char 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() : char formats with float values ***\n";
11
12// array of float values
13$float_values = array(
14  0.0,
15  -0.1,
16  1.0,
17  1e5,
18  -1e6,
19  1E8,
20  -1E9,
21  10.5e+5
22);
23
24// array of char formats
25$char_formats = array(
26  "%c", "%hc", "%lc",
27  "%Lc", " %c", "%c ",
28  "\t%c", "\n%c", "%4c",
29  "%30c", "%[a-bA-B@#$&]", "%*c"
30);
31
32$count = 1;
33foreach($float_values as $float_value) {
34  echo "\n-- Iteration $count --\n";
35
36  foreach($char_formats as $format) {
37    var_dump( sprintf($format, $float_value) );
38  }
39  $count++;
40};
41
42echo "Done";
43?>
44--EXPECTF--
45*** Testing sprintf() : char formats with float values ***
46
47-- Iteration 1 --
48string(1) "�"
49string(1) "c"
50string(1) "�"
51string(1) "c"
52string(2) " �"
53string(2) "� "
54string(2) "	�"
55string(2) "
56�"
57string(1) "�"
58string(1) "�"
59string(11) "a-bA-B@#$&]"
60string(1) "c"
61
62-- Iteration 2 --
63string(1) "�"
64string(1) "c"
65string(1) "�"
66string(1) "c"
67string(2) " �"
68string(2) "� "
69string(2) "	�"
70string(2) "
71�"
72string(1) "�"
73string(1) "�"
74string(11) "a-bA-B@#$&]"
75string(1) "c"
76
77-- Iteration 3 --
78string(1) ""
79string(1) "c"
80string(1) ""
81string(1) "c"
82string(2) " "
83string(2) " "
84string(2) "	"
85string(2) "
86"
87string(1) ""
88string(1) ""
89string(11) "a-bA-B@#$&]"
90string(1) "c"
91
92-- Iteration 4 --
93string(1) "�"
94string(1) "c"
95string(1) "�"
96string(1) "c"
97string(2) " �"
98string(2) "� "
99string(2) "	�"
100string(2) "
101�"
102string(1) "�"
103string(1) "�"
104string(11) "a-bA-B@#$&]"
105string(1) "c"
106
107-- Iteration 5 --
108string(1) "�"
109string(1) "c"
110string(1) "�"
111string(1) "c"
112string(2) " �"
113string(2) "� "
114string(2) "	�"
115string(2) "
116�"
117string(1) "�"
118string(1) "�"
119string(11) "a-bA-B@#$&]"
120string(1) "c"
121
122-- Iteration 6 --
123string(1) "�"
124string(1) "c"
125string(1) "�"
126string(1) "c"
127string(2) " �"
128string(2) "� "
129string(2) "	�"
130string(2) "
131�"
132string(1) "�"
133string(1) "�"
134string(11) "a-bA-B@#$&]"
135string(1) "c"
136
137-- Iteration 7 --
138string(1) "�"
139string(1) "c"
140string(1) "�"
141string(1) "c"
142string(2) " �"
143string(2) "� "
144string(2) "	�"
145string(2) "
146�"
147string(1) "�"
148string(1) "�"
149string(11) "a-bA-B@#$&]"
150string(1) "c"
151
152-- Iteration 8 --
153string(1) "�"
154string(1) "c"
155string(1) "�"
156string(1) "c"
157string(2) " �"
158string(2) "� "
159string(2) "	�"
160string(2) "
161�"
162string(1) "�"
163string(1) "�"
164string(11) "a-bA-B@#$&]"
165string(1) "c"
166Done