xref: /PHP-7.1/tests/strings/002.phpt (revision 7af945e2)
1--TEST--
2Formatted print functions
3--FILE--
4<?php
5error_reporting(0);
6
7$fp = fopen("php://stdout", "w") or die("Arrggsgg!!");
8$x = fprintf($fp, "fprintf test 1:%.5s", "abcdefghij");
9echo "\n";
10var_dump($x);
11
12printf("printf test 1:%s\n", "simple string");
13printf("printf test 2:%d\n", 42);
14printf("printf test 3:%f\n", 10.0/3);
15printf("printf test 4:%.10f\n", 10.0/3);
16printf("printf test 5:%-10.2f\n", 2.5);
17printf("printf test 6:%-010.2f\n", 2.5);
18printf("printf test 7:%010.2f\n", 2.5);
19printf("printf test 8:<%20s>\n", "foo");
20printf("printf test 9:<%-20s>\n", "bar");
21printf("printf test 10: 123456789012345\n");
22printf("printf test 10:<%15s>\n", "h�yesterettsjustitiarius");
23printf("printf test 11: 123456789012345678901234567890\n");
24printf("printf test 11:<%30s>\n", "h�yesterettsjustitiarius");
25printf("printf test 12:%5.2f\n", -12.34);
26printf("printf test 13:%5d\n", -12);
27printf("printf test 14:%c\n", 64);
28printf("printf test 15:%b\n", 170);
29printf("printf test 16:%x\n", 170);
30printf("printf test 17:%X\n", 170);
31printf("printf test 18:%16b\n", 170);
32printf("printf test 19:%16x\n", 170);
33printf("printf test 20:%16X\n", 170);
34printf("printf test 21:%016b\n", 170);
35printf("printf test 22:%016x\n", 170);
36printf("printf test 23:%016X\n", 170);
37printf("printf test 24:%.5s\n", "abcdefghij");
38printf("printf test 25:%-2s\n", "gazonk");
39printf("printf test 26:%2\$d %1\$d\n", 1, 2);
40printf("printf test 27:%3\$d %d %d\n", 1, 2, 3);
41printf("printf test 28:%2\$02d %1\$2d\n", 1, 2);
42printf("printf test 29:%2\$-2d %1\$2d\n", 1, 2);
43print("printf test 30:"); printf("%0\$s", 1); print("x\n");
44vprintf("vprintf test 1:%2\$-2d %1\$2d\n", array(1, 2));
45
46
47?>
48--EXPECT--
49fprintf test 1:abcde
50int(20)
51printf test 1:simple string
52printf test 2:42
53printf test 3:3.333333
54printf test 4:3.3333333333
55printf test 5:2.50
56printf test 6:2.50000000
57printf test 7:0000002.50
58printf test 8:<                 foo>
59printf test 9:<bar                 >
60printf test 10: 123456789012345
61printf test 10:<h�yesterettsjustitiarius>
62printf test 11: 123456789012345678901234567890
63printf test 11:<      h�yesterettsjustitiarius>
64printf test 12:-12.34
65printf test 13:  -12
66printf test 14:@
67printf test 15:10101010
68printf test 16:aa
69printf test 17:AA
70printf test 18:        10101010
71printf test 19:              aa
72printf test 20:              AA
73printf test 21:0000000010101010
74printf test 22:00000000000000aa
75printf test 23:00000000000000AA
76printf test 24:abcde
77printf test 25:gazonk
78printf test 26:2 1
79printf test 27:3 1 2
80printf test 28:02  1
81printf test 29:2   1
82printf test 30:x
83vprintf test 1:2   1
84