Student A

[article] [edit page] [discussion] [history]

From Humanitarian-FOSS Project Development Site

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html401/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>12 Days Of Christmas</title>
	</head>
	<body bgcolor="#aaffaa" text="#ff4444">
		<h1>The 12 Days Of Christmas</h1>
		<script language="PHP">
			$days = array(1=>"first", "second", "third", "fourth", "fifth",
					"sixth", "seventh", "eighth", "ninth", "tenth",
					"eleventh", "twelfth");
			$numbers = array(1=>"a", "two", "three", "four", "five", "six",
					"seven", "eight", "nine", "ten", "eleven", "twelve");
			$gifts = array(1=>"partridge in a pear tree", "turtledoves", "French hens",
					"calling birds", "golden rings", "geese", "swans", "maids",
					"ladies", "lords", "pipers", "drummers");
			$actions = array(6=>"a-laying", "a-swimming", "a-milking", "dancing",
					"a-leaping", "piping", "drumming");
			/* Construct lines of song and store in assoc. array like so:
				day => line
				e.g. "twelfth" => "twelve drummers drumming" */
			$lines = array();
			foreach ($days as $index => $day) {
				$lines[$day] = $numbers[$index] . " " . $gifts[$index];
				if (isset($actions[$index]))
					$lines[$day] .= " " . $actions[$index];
			}
			/* Start singing! */
			for ($index = 1; $index <= 12; $index++) {
				echo("On the " . $days[$index] .
					" day of Christmas my true love gave to me:<br>");
				echo(list_of_schwag($days[$index]));
				echo("<br>");
			}

			function list_of_schwag($day) {
				global $lines, $days;
				$list = ".<br>"; // start from end & build backward
				foreach($lines as $index=>$line) {
					switch($index) {
					//  get text between this line & next (if any):
					case $days[1]:
						$separator = "";
						break;
					case $days[2]:
						$separator = ", <br> and ";
						break;
					default:
						$separator = ", <br>";
					}
					$list = $lines[$index] . $separator . $list;
					if ($index == $day)
						return $list;
				}
			}
		</script>
	</body>
</html>
Personal tools