-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnameplay.php
More file actions
81 lines (58 loc) · 1.84 KB
/
nameplay.php
File metadata and controls
81 lines (58 loc) · 1.84 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
<?php
//************************************************************
//************************************************************
// The Functions
//************************************************************
//************************************************************
// Create the name game function
function name_game($name) {
//define vowels
$vowels = ['a','e','i','o','u'];
$song = '';
if(array_search(strtolower($name[0]), $vowels) !== false) {
$song .= "{$name}!" . PHP_EOL .
"{$name}, {$name} bo B" . strtolower($name) . PHP_EOL .
"Bonana fanna fo F" . strtolower($name) . PHP_EOL .
"Fee fy mo M" . strtolower($name) . "," . PHP_EOL .
"{$name}! ";
} else {
$song .= "{$name}!" . PHP_EOL .
"{$name}, {$name} bo B" . strtolower(substr($name, 1)) . PHP_EOL .
"Bonana fanna fo F" . strtolower(substr($name, 1)) . PHP_EOL .
"Fee fy mo M" . strtolower(substr($name, 1)) . "," . PHP_EOL .
"{$name}! ";
}
return $song;
}
//grab user's name
function get_name() {
echo "What is your name? ";
$name = (trim(fgets(STDIN)));
return $name;
}
// function to make sure name is a name.
function check_name($name) {
if(is_numeric($name)) {
echo "Play Fair!!!\n";
exit(1);
}
if(empty($name)) {
echo "You must enter a name!\n";
exit(1);
}
}
//************************************************************
//************************************************************
// Here is the actual game!!
//************************************************************
//************************************************************
echo "Let's play the name game!!\n";
// Prompt the User for their name.
$name = get_name();
// Make sure they gave you a word with which the name game is possible.
check_name($name);
// Here is the name game!!
echo name_game($name);
echo PHP_EOL;
exit(0);
?>