1--TEST--
2Test sprintf() function : usage variations - string 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
10
11echo "*** Testing sprintf() : string formats with string values ***\n";
12
13// defining different heredoc strings
14/* string created using Heredoc (<<<) */
15$heredoc_string = <<<EOT
16This is string defined
17using heredoc.
18EOT;
19
20/* heredoc string with only numerics */
21$heredoc_numeric_string = <<<EOT
22123456 3993
234849 string
24EOT;
25
26/* null heardoc string */
27$heredoc_empty_string = <<<EOT
28EOT;
29$heredoc_null_string = <<<EOT
30NULL
31EOT;
32
33// array of strings used to test the function
34$string_values = array(
35  "",
36  " ",
37  '',
38  ' ',
39  "string",
40  'string',
41  "NULL",
42  'null',
43  "FALSE",
44  'true',
45  "\x0b",
46  "\0",
47  '\0',
48  '\060',
49  "\070",
50  "0x55F",
51  "055",
52  "@#$#$%%$^^$%^%^$^&",
53  $heredoc_string,
54  $heredoc_numeric_string,
55  $heredoc_empty_string,
56  $heredoc_null_string
57);
58
59// array of string formats
60$string_formats = array(
61  "%s", "%hs", "%ls",
62  "%Ls"," %s", "%s ",
63  "\t%s", "\n%s", "%4s",
64  "%30s", "%[a-zA-Z0-9]", "%*s"
65);
66
67$count = 1;
68foreach($string_values as $string_value) {
69  echo "\n-- Iteration $count --\n";
70
71  foreach($string_formats as $format) {
72    var_dump( sprintf($format, $string_value) );
73  }
74  $count++;
75};
76
77echo "Done";
78?>
79--EXPECTF--
80*** Testing sprintf() : string formats with string values ***
81
82-- Iteration 1 --
83string(0) ""
84string(1) "s"
85string(0) ""
86string(1) "s"
87string(1) " "
88string(1) " "
89string(1) "	"
90string(1) "
91"
92string(4) "    "
93string(30) "                              "
94string(10) "a-zA-Z0-9]"
95string(1) "s"
96
97-- Iteration 2 --
98string(1) " "
99string(1) "s"
100string(1) " "
101string(1) "s"
102string(2) "  "
103string(2) "  "
104string(2) "	 "
105string(2) "
106 "
107string(4) "    "
108string(30) "                              "
109string(10) "a-zA-Z0-9]"
110string(1) "s"
111
112-- Iteration 3 --
113string(0) ""
114string(1) "s"
115string(0) ""
116string(1) "s"
117string(1) " "
118string(1) " "
119string(1) "	"
120string(1) "
121"
122string(4) "    "
123string(30) "                              "
124string(10) "a-zA-Z0-9]"
125string(1) "s"
126
127-- Iteration 4 --
128string(1) " "
129string(1) "s"
130string(1) " "
131string(1) "s"
132string(2) "  "
133string(2) "  "
134string(2) "	 "
135string(2) "
136 "
137string(4) "    "
138string(30) "                              "
139string(10) "a-zA-Z0-9]"
140string(1) "s"
141
142-- Iteration 5 --
143string(6) "string"
144string(1) "s"
145string(6) "string"
146string(1) "s"
147string(7) " string"
148string(7) "string "
149string(7) "	string"
150string(7) "
151string"
152string(6) "string"
153string(30) "                        string"
154string(10) "a-zA-Z0-9]"
155string(1) "s"
156
157-- Iteration 6 --
158string(6) "string"
159string(1) "s"
160string(6) "string"
161string(1) "s"
162string(7) " string"
163string(7) "string "
164string(7) "	string"
165string(7) "
166string"
167string(6) "string"
168string(30) "                        string"
169string(10) "a-zA-Z0-9]"
170string(1) "s"
171
172-- Iteration 7 --
173string(4) "NULL"
174string(1) "s"
175string(4) "NULL"
176string(1) "s"
177string(5) " NULL"
178string(5) "NULL "
179string(5) "	NULL"
180string(5) "
181NULL"
182string(4) "NULL"
183string(30) "                          NULL"
184string(10) "a-zA-Z0-9]"
185string(1) "s"
186
187-- Iteration 8 --
188string(4) "null"
189string(1) "s"
190string(4) "null"
191string(1) "s"
192string(5) " null"
193string(5) "null "
194string(5) "	null"
195string(5) "
196null"
197string(4) "null"
198string(30) "                          null"
199string(10) "a-zA-Z0-9]"
200string(1) "s"
201
202-- Iteration 9 --
203string(5) "FALSE"
204string(1) "s"
205string(5) "FALSE"
206string(1) "s"
207string(6) " FALSE"
208string(6) "FALSE "
209string(6) "	FALSE"
210string(6) "
211FALSE"
212string(5) "FALSE"
213string(30) "                         FALSE"
214string(10) "a-zA-Z0-9]"
215string(1) "s"
216
217-- Iteration 10 --
218string(4) "true"
219string(1) "s"
220string(4) "true"
221string(1) "s"
222string(5) " true"
223string(5) "true "
224string(5) "	true"
225string(5) "
226true"
227string(4) "true"
228string(30) "                          true"
229string(10) "a-zA-Z0-9]"
230string(1) "s"
231
232-- Iteration 11 --
233string(1) ""
234string(1) "s"
235string(1) ""
236string(1) "s"
237string(2) " "
238string(2) " "
239string(2) "	"
240string(2) "
241"
242string(4) "   "
243string(30) "                             "
244string(10) "a-zA-Z0-9]"
245string(1) "s"
246
247-- Iteration 12 --
248string(1) "�"
249string(1) "s"
250string(1) "�"
251string(1) "s"
252string(2) " �"
253string(2) "� "
254string(2) "	�"
255string(2) "
256�"
257string(4) "   �"
258string(30) "                             �"
259string(10) "a-zA-Z0-9]"
260string(1) "s"
261
262-- Iteration 13 --
263string(2) "\0"
264string(1) "s"
265string(2) "\0"
266string(1) "s"
267string(3) " \0"
268string(3) "\0 "
269string(3) "	\0"
270string(3) "
271\0"
272string(4) "  \0"
273string(30) "                            \0"
274string(10) "a-zA-Z0-9]"
275string(1) "s"
276
277-- Iteration 14 --
278string(4) "\060"
279string(1) "s"
280string(4) "\060"
281string(1) "s"
282string(5) " \060"
283string(5) "\060 "
284string(5) "	\060"
285string(5) "
286\060"
287string(4) "\060"
288string(30) "                          \060"
289string(10) "a-zA-Z0-9]"
290string(1) "s"
291
292-- Iteration 15 --
293string(1) "8"
294string(1) "s"
295string(1) "8"
296string(1) "s"
297string(2) " 8"
298string(2) "8 "
299string(2) "	8"
300string(2) "
3018"
302string(4) "   8"
303string(30) "                             8"
304string(10) "a-zA-Z0-9]"
305string(1) "s"
306
307-- Iteration 16 --
308string(5) "0x55F"
309string(1) "s"
310string(5) "0x55F"
311string(1) "s"
312string(6) " 0x55F"
313string(6) "0x55F "
314string(6) "	0x55F"
315string(6) "
3160x55F"
317string(5) "0x55F"
318string(30) "                         0x55F"
319string(10) "a-zA-Z0-9]"
320string(1) "s"
321
322-- Iteration 17 --
323string(3) "055"
324string(1) "s"
325string(3) "055"
326string(1) "s"
327string(4) " 055"
328string(4) "055 "
329string(4) "	055"
330string(4) "
331055"
332string(4) " 055"
333string(30) "                           055"
334string(10) "a-zA-Z0-9]"
335string(1) "s"
336
337-- Iteration 18 --
338string(18) "@#$#$%%$^^$%^%^$^&"
339string(1) "s"
340string(18) "@#$#$%%$^^$%^%^$^&"
341string(1) "s"
342string(19) " @#$#$%%$^^$%^%^$^&"
343string(19) "@#$#$%%$^^$%^%^$^& "
344string(19) "	@#$#$%%$^^$%^%^$^&"
345string(19) "
346@#$#$%%$^^$%^%^$^&"
347string(18) "@#$#$%%$^^$%^%^$^&"
348string(30) "            @#$#$%%$^^$%^%^$^&"
349string(10) "a-zA-Z0-9]"
350string(1) "s"
351
352-- Iteration 19 --
353string(37) "This is string defined
354using heredoc."
355string(1) "s"
356string(37) "This is string defined
357using heredoc."
358string(1) "s"
359string(38) " This is string defined
360using heredoc."
361string(38) "This is string defined
362using heredoc. "
363string(38) "	This is string defined
364using heredoc."
365string(38) "
366This is string defined
367using heredoc."
368string(37) "This is string defined
369using heredoc."
370string(37) "This is string defined
371using heredoc."
372string(10) "a-zA-Z0-9]"
373string(1) "s"
374
375-- Iteration 20 --
376string(23) "123456 3993
3774849 string"
378string(1) "s"
379string(23) "123456 3993
3804849 string"
381string(1) "s"
382string(24) " 123456 3993
3834849 string"
384string(24) "123456 3993
3854849 string "
386string(24) "	123456 3993
3874849 string"
388string(24) "
389123456 3993
3904849 string"
391string(23) "123456 3993
3924849 string"
393string(30) "       123456 3993
3944849 string"
395string(10) "a-zA-Z0-9]"
396string(1) "s"
397
398-- Iteration 21 --
399string(0) ""
400string(1) "s"
401string(0) ""
402string(1) "s"
403string(1) " "
404string(1) " "
405string(1) "	"
406string(1) "
407"
408string(4) "    "
409string(30) "                              "
410string(10) "a-zA-Z0-9]"
411string(1) "s"
412
413-- Iteration 22 --
414string(4) "NULL"
415string(1) "s"
416string(4) "NULL"
417string(1) "s"
418string(5) " NULL"
419string(5) "NULL "
420string(5) "	NULL"
421string(5) "
422NULL"
423string(4) "NULL"
424string(30) "                          NULL"
425string(10) "a-zA-Z0-9]"
426string(1) "s"
427Done