-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHPFunctions.php
More file actions
58 lines (51 loc) · 1.59 KB
/
PHPFunctions.php
File metadata and controls
58 lines (51 loc) · 1.59 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
<html>
<head>
<title>PHP Functions</title>
</head>
<body>
<?php
// Declare functions
function dateMDY() : string{
$dateMDY = date("m/d/y");
return $dateMDY;
}
function dateDMY() : string{
$dateDMY = date("d/m/y");
return $dateDMY;
}
function multiString(string $x){
echo '<ul>';
echo '<li>Number of characters: ', strlen($x), '</li>';
echo '<li>Trimmed whitespace: ', trim($x), '</li>';
echo '<li>All lowercase: ', strtolower($x), '</li>';
echo '<li>Contains DMACC: ';
if (strripos($x, "DMACC") === false) {
echo 'No';
}
else {
echo 'Yes';
}
echo '</li></ul>';
}
function phoneNum(string $p){
$result = sprintf("%s-%s-%s",
substr($p, 0, 3),
substr($p, 3, 3),
substr($p, 6));
echo "<p>Phone number: ", $result, "</p>";
}
function moneyNum(int $m) {
echo '<p>$', $m, '<p>';
}
?>
<h1>4-1: PHP Functions</h1>
<?php
// Call functions
echo '<p>', dateMDY(), '</p>';
echo '<p>', dateDMY(), '</p>';
multiString(' DMACC is cool ');
phoneNum('1234567890');
moneyNum(123456);
?>
</body>
</html>