-
Notifications
You must be signed in to change notification settings - Fork 4
/
sprintf.php
74 lines (57 loc) · 1.15 KB
/
sprintf.php
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
70
71
72
73
74
<?php
// sprintf
// %d
// %s
// %f
$str = sprintf("%s %s", "Hello", "World");
var_dump($str);
$str = sprintf("%s<---->%s", "Hello", "World");
var_dump($str);
$str = sprintf("hi, there, it's me? HOW ARE YOU?\n%s (%d)", "Hello", 100);
var_dump($str);
$str = sprintf("hi, there, it's me? HOW ARE YOU?");
var_dump($str);
$str = "Hello" . " " . "World";
var_dump($str);
$age = 100;
$str = "Hello $age";
var_dump($str);
function testme() {
return "MAX";
}
$age = 100;
$str = "Hello $age" . testme();
var_dump($str);
$age = 100;
$str = "Hello {$age} testme()";
var_dump($str);
$list = [
"ali",
"reza",
"hamid"
];
$str = "Hello {$list[0]} {$list[1]} {$list[2]}";
var_dump($str);
// $age = 10;
// Error: $str = "$agehi";
// var_dump($str);
$age = 10;
$str = "$age hi";
var_dump($str);
$age = 10;
$str = "$age" . " hi";
var_dump($str);
$age = 10;
$str = $age . " hi";
var_dump($str);
$age = 10;
$str = "{$age}hi";
var_dump($str);
var_dump(sprintf("%d", "100"));
var_dump(sprintf("%f", 3.14));
var_dump(sprintf("%g", 3.14));
var_dump(sprintf("%.3f", 3.14));
var_dump(sprintf("%.3f", 10));
// string s
// int d, u, c, o, x, X, b
// float e, E, f, F, g, G, h, H