-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
112 lines (71 loc) · 2.27 KB
/
functions.php
File metadata and controls
112 lines (71 loc) · 2.27 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<p style="color: blue;">Use a function that capitalizes the first letter of the provided argument. Example: should return "émile""Émile"
</p>
<?php
if (!function_exists('mb_ucfirst') && function_exists('mb_substr')) {
function mb_ucfirst($string)
{
$string = mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
return $string;
}
}
$name = "émile";
$name = mb_ucfirst($name);
echo $name;
?>
<hr>
<p style="color: blue;">Use the native function allowing you to display the current year.</p>
<?php
echo date("Y");
?>
<hr>
<p style="color: blue;">Now display the date, time, minutes and seconds, using the same function, by playing with the arguments.</p>
<?php
$today = date("F j, Y, g:i a");
echo $today;
?>
<hr>
<p style="color: blue;">Create a "Sum" function that takes 2 numbers and returns their sum.</p>
<?php
$a = 1;
$b = 2;
echo $a + $b;
?>
<hr>
<p style="color: blue;">Improve that function so that it checks whether the argument is indeed a Number. If not, it should display : "Error: argument is not a number."</p>
<?php
$a = 1;
$b = 2;
$tests = array(
$a,
$b
);
foreach ($tests as $element) {
if (is_numeric($element)) {
echo var_export($element, true) . " is numeric";
} else {
echo var_export($element, true) . "Error: argument is not a number";
}
}
?>
<hr>
<p style="color: blue;">Create a function that takes as argument a string of characters and returns an acronym made of the initials of each word.
Example: "In code we trust!" should return: ICWT).</p>
<?php
$s = 'In code we trust!';
$s = strtoupper($s);
echo preg_replace('/\b(\w)|./', '$1', $s);
?>
<hr>
<p style="color: blue;">Create a function that replaces the letters "a" and "e" with "æ". Example: "caecotrophie", "chaenichthys","microsphaera", "sphaerotheca" should respectively return "cæcotrophie", "chænichthys","microsphæra", "sphærotheca".</p>
<?php
$words = ['caecotrophie', 'chaenichthys', 'microsphaera', 'sphaerotheca'];
$words = str_replace('ae', 'æ', $words);
var_dump($words);
?>
<hr>
<p style="color: blue;">Create the opposite function, which replaces "æ" by "ae" in : cæcotrophie, chænichthys, microsphæra, sphærotheca</p>
<?php
$words = str_replace('æ', 'ae', $words);
var_dump($words);
?>
<hr>