-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmbeddedWorks.php
78 lines (73 loc) · 2.2 KB
/
EmbeddedWorks.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
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>Embedded Works</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<?php include 'includes/inc_header.php'; ?>
<h1>Embedded Works</h1><hr />
<?php
$Phrases = array(
"Your Chinese zodiac sign tells a lot about
your personality.",
"Embed PHP scripts within an XHTML
document.");
$SignNames = array(
"Rat",
"Ox",
"Tiger",
"Rabbit",
"Dragon",
"Snake",
"Horse",
"Goat",
"Monkey",
"Rooster",
"Dog",
"Pig");
function BuildLetterCounts($text) {
$text = strtoupper($text);
$letter_counts = count_chars($text);
return $letter_counts;
}
function AContainsB($A, $B) {
$retval = TRUE;
$first_letter_index = ord('A');
$last_letter_index = ord('Z');
for ($letter_index = $first_letter_index;
$letter_index <= $last_letter_index;
++$letter_index) {
if ($A[$letter_index] < $B[$letter_index]) {
$retval = FALSE;
}
}
return $retval;
}
foreach ($Phrases as $Phrase) {
$PhraseArray = BuildLetterCounts($Phrase);
$GoodWords = array();
$BadWords = array();
foreach ($SignNames as $Word) {
$WordArray = BuildLetterCounts($Word);
if (AContainsB($PhraseArray, $WordArray))
$GoodWords[] = $Word;
else
$BadWords[] = $Word;
}
echo "<p>The following words can be made from the letters in the phrase "$Phrase":";
foreach ($GoodWords as $Word)
echo " $Word";
echo "</p>\n";
echo "<p>The following words can not be made from the letters in the phrase "$Phrase":";
foreach ($BadWords as $Word)
echo " $Word";
echo "</p>\n";
echo "<hr />\n";
}
?>
<?php include 'includes/inc_footer.php'; ?>
</div>
</body>
</html>