summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/001.phpt
blob: e84622902c3b2ded03a39292a7c81b4b47a90657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--TEST--
sprintf() function
--POST--
--GET--
--FILE--
<?php 

$agent = sprintf("%.5s", "James Bond, 007");

echo("sprintf string truncate test:   ");
if ($agent == "James") {
	echo("passed\n");
} else {
	echo("failed!\n");
}

echo("sprintf padding and align test: ");
$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
if ($test == "abc0020 fisketur            !") {
	echo("passed\n");
} else {
	echo("failed!\n");
}

echo("sprintf octal and hex test:     ");
$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
if ($test == " 200  400 BFFF 0034c385") {
	echo("passed\n");
} else {
	echo("failed!\n");
}

echo("sprintf octal binary test:      ");
$test = sprintf("%b", 3457925);
if ($test == "1101001100001110000101") {
	echo("passed\n");
} else {
	echo("failed!\n");
}

echo("sprintf float test:             ");
$test = sprintf("%0"."06.2f", 10000/3.0);
if ($test == "003333.33") {
	echo("passed\n");
} else {
	echo("failed!\n");
}

echo sprintf("%.2f\n", "99.00");
echo sprintf("%.2f\n", 99.00);

echo sprintf("%e\n", 1.234E-18);
echo sprintf("%e\n", 1.234E+18);
echo sprintf("%e\n", 9843243.12);
echo sprintf("%e\n", -9843243.12);

?>
--EXPECT--
sprintf string truncate test:   passed
sprintf padding and align test: passed
sprintf octal and hex test:     passed
sprintf octal binary test:      passed
sprintf float test:             passed
99.00
99.00
1.23400e-18
1.23400e+18
9.84324e+6
-9.84324e+6