Hello,
I have this project for one of my classes and I need this code to basically show me the chinese zodiac animal names that can be made from "Your Chinese zodiac sign tells a lot about your personality.", "Embed PHP scripts within an XHTML document."
I only have the one part working: Embed PHP scripts within an XHTML document.
For some reason I'm not really catching what is not making the Your Chinese zodiac sign tells a lot about your personality phrase. Here's the code, I'm tweeking it a little bit, and I believe I have everything typed correctly, but I'm just not catching it. Any help would be much appreciated 😃
$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", "Ram", "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 cannot be made from the letters in the phrase "$Phrase" :";
foreach($BadWords as $Word)
echo " $Word";
echo "</p>\n";
echo "<hr />\n";