-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallengeFunctions.php
More file actions
264 lines (236 loc) · 5.24 KB
/
challengeFunctions.php
File metadata and controls
264 lines (236 loc) · 5.24 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
function myquote()
{
$quote = "<p>\"A computer once beat me at chess, but it was no match for me at kick boxing.\"<br />\n - Emo Philips</p>";
print $quote;
}
function myquote2()
{
$quote = "<p>\"Curiosity killed the cat, but for a while I was a suspect.\"<br />\n - Steven Wright</p>";
return $quote;
}
function print_name1()
{
print $_GET['name'];
}
function print_name2()
{
if (isset($_GET['name']))
{
print $_GET['name'];
}
}
function print_name3()
{
if (isset($_POST['name']))
{
print $_POST['name'];
}
else
{
print "<p>You didn't type anything in the <a href='form3.html'>form</a></p>";
}
}
function print_name4()
{
if (isset($_POST['name']))
{
$name = $_POST['name'];
print "<p><span style='color:blue;'>You typed:</span> $name</p>";
}
else
{
print "<p>You didn't type anything in the <a href='form5.html'>form</a></p>";
}
}
function print_name5()
{
if (isset($_POST['name']))
{
$name = strtolower($_POST['name']);
print "<p><span style='color:blue;'>You typed:</span> $name</p>";
}
else
{
print "<p>You didn't type anything in the <a href='form5.html'>form</a></p>";
}
}
function print_name6()
{
if (isset($_POST['name']))
{
$name = ucwords(strtolower($_POST['name']));
print "<p><span style='color:blue;'>You typed:</span> $name</p>";
}
else
{
print "<p>You didn't type anything in the <a href='form6.html'>form</a></p>";
}
}
function selectPhoto()
{
$photo_array = array("pict01.jpg", "pict02.jpg", "pict03.jpg", "pict04.jpg", "pict05.jpg", "pict06.jpg", "pict07.jpg");
$random_photo = $photo_array[rand(0,6)];
print "<img src = 'http://meadpoint.net/phpchallenges/images/$random_photo' alt='random pict' />";
}
function selectPhoto2()
{
$photo_array = array("pict01.jpg", "pict02.jpg", "pict03.jpg", "pict04.jpg", "pict05.jpg", "pict06.jpg", "pict07.jpg");
$random_photo = $photo_array[rand(0,6)];
return $random_photo;
}
function displayFilenames()
{
$photo_array = array("pict01.jpg", "pict02.jpg", "pict03.jpg", "pict04.jpg", "pict05.jpg", "pict06.jpg", "pict07.jpg");
foreach($photo_array as $temp)
{
print $temp;
print "<br />";
}
}
function processForm1()
{
$regex_integers_only = "/^[-+]?[0-9]\d*\.?[0]*$/";
$number = $_POST['number'];
if(preg_match($regex_integers_only, $number))
{
print "<p>You typed the number: $number</p>";
}
else
{
print "<p>not sure what you typed, but it was not a whole number.</p>";
}
}
function processForm2()
{
$regex_integers_only = "/^[-+]?[0-9]\d*\.?[0]*$/";
if(isset($_POST['number']))
{
$number = $_POST['number'];
if(preg_match($regex_integers_only, $number))
{
print "<p>You typed the number: $number</p>";
}
else
{
print "<p>not sure what you typed, but it was not a whole number.</p>";
}
}
else
{
print "<p>please for god's sake enter something into the <a href='form8.html'>form!</a></p>";
}
}
function processForm3()
{
$regex_email_only = "/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/";
if(isset($_POST['email']))
{
$email = $_POST['email'];
if(preg_match($regex_email_only, $email))
{
print "<p>You typed this email address: $email</p>";
}
else
{
print "<p>not sure what you typed, but it was not an email address.</p>";
}
}
else
{
print "<p>please for god's sake enter something into the <a href='form9.html'>form!</a></p>";
}
}
function processForm4()
{
$regex_integers_only = "/^[-+]?[0-9]\d*\.?[0]*$/";
if(isset($_POST['number']))
{
$number = $_POST['number'];
if(preg_match($regex_integers_only, $number))
{
print "<p>You typed the number: $number</p>";
if($number % 2 == 0)
{
print "<p>$number is an even number</p>";
}
else
{
print "<p>$number is an odd number</p>";
}
}
else
{
print "<p>not sure what you typed, but it was not a whole number.</p>";
}
}
else
{
print "<p>please for god's sake enter something into the <a href='form10.html'>form!</a></p>";
}
}
function processForm5()
{
$regex_integers_only = "/^[-+]?[0-9]\d*\.?[0]*$/";
if(isset($_POST['number']))
{
$number = $_POST['number'];
if(preg_match($regex_integers_only, $number))
{
if($number % 2 == 0)
{
print "<p style='color:blue;'>You typed the number: $number</p>";
}
else
{
print "<p style='color:red;'>You typed the number: $number</p>";
}
}
else
{
print "<p>not sure what you typed, but it was not a whole number.</p>";
}
}
else
{
print "<p>please for god's sake enter something into the <a href='form11.html'>form!</a></p>";
}
}
function printChoices($col)
{
$selected = $_POST['animal'];
$counter = 1;
echo "<table border = '1'>\n";
echo "<tr>\n";
foreach($selected as $temp)
{
echo "<td>$temp</td>";
if ($counter == count($selected))
{
echo "\n</tr>\n</table>\n";
}
elseif ($counter % $col == 0)
{
echo "\n</tr>\n<tr>\n";
}
$counter++;
}
}
function createTable()
{
$submitted_data = $_POST['textarea'];
echo "<table border = '1'>\n";
$each_row = split(";", $submitted_data); //$each_row is now an array of however many elements
foreach($each_row as $row)
{
echo "<tr>\n";
$each_item = split(",", $row);
foreach($each_item as $item)
{
echo "<td>$item</td>";
}
echo "\n</tr>\n";
}
echo "</table>";
}
?>