1--TEST--
2sprintf() function
3--FILE--
4<?php
5
6$agent = sprintf("%.5s", "James Bond, 007");
7
8echo("sprintf string truncate test:   ");
9if ($agent == "James") {
10	echo("passed\n");
11} else {
12	echo("failed!\n");
13}
14
15echo("sprintf padding and align test: ");
16$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
17if ($test == "abc0020 fisketur            !") {
18	echo("passed\n");
19} else {
20	echo("failed!\n");
21}
22
23echo("sprintf octal and hex test:     ");
24$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
25if ($test == " 200  400 BFFF 0034c385") {
26	echo("passed\n");
27} else {
28	echo("failed!\n");
29}
30
31echo("sprintf octal binary test:      ");
32$test = sprintf("%b", 3457925);
33if ($test == "1101001100001110000101") {
34	echo("passed\n");
35} else {
36	echo("failed!\n");
37}
38
39echo("sprintf float test:             ");
40$test = sprintf("%0"."06.2f", 10000/3.0);
41if ($test == "003333.33") {
42	echo("passed\n");
43} else {
44	echo("failed!\n");
45}
46
47echo sprintf("%.2f\n", "99.00");
48echo sprintf("%.2f\n", 99.00);
49
50echo sprintf("%e\n", 1.234E-18);
51echo sprintf("%e\n", 1.234E+18);
52echo sprintf("%e\n", 9843243.12);
53echo sprintf("%e\n", -9843243.12);
54
55?>
56--EXPECT--
57sprintf string truncate test:   passed
58sprintf padding and align test: passed
59sprintf octal and hex test:     passed
60sprintf octal binary test:      passed
61sprintf float test:             passed
6299.00
6399.00
641.234000e-18
651.234000e+18
669.843243e+6
67-9.843243e+6
68