Created
April 6, 2012 22:32
-
-
Save griffiths/2323575 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// retrieve values passed from our form and store them in PHP variables | |
$first = $_REQUEST["name"]; | |
$color = $_REQUEST["color"]; | |
$month = $_REQUEST["month"]; | |
$number = $_REQUEST["number"]; | |
// Set the value of our bgcolor variable based on the month selected by the user | |
if ($month == "jan") { | |
$bgcolor = "blue"; | |
} | |
if ($month == "feb") { | |
$bgcolor = "purple"; | |
} | |
if ($month == "mar") { | |
$bgcolor = "gray"; | |
} | |
if ($month == "apr") { | |
$bgcolor = "pink"; | |
} | |
if ($month == "may") { | |
$bgcolor = "orange"; | |
} | |
if ($month == "jun") { | |
$bgcolor = "aquamarine"; | |
} | |
if ($month == "jul") { | |
$bgcolor = "salmon"; | |
} | |
?> | |
<html> | |
<head> | |
<title>Result</title> | |
</head> | |
<body style="background-color:<?php | |
// prints our background color as an inline style | |
echo $bgcolor; | |
?>;"> | |
<?php | |
// Print the user's name and their favorite color | |
//echo "My name is " . $first . " and my favorite color is " . $color . "."; | |
// Print the length of the user's name | |
//echo strlen($first); | |
//Building a loop, setting our counter to 1 | |
$count = 1; | |
// Our loop will be performed while our counter is less than or equal to the number of characters in the user's name | |
while ($count <= strlen($first)) { | |
// Compute our opacity value by dividing the current value of the counter by the number of characters in the user's name | |
$opacity = $count / strlen($first); | |
// Print our div, with an inline style to set our opacity | |
echo "<div style='opacity:" . $opacity . ";>'>My name is " . $first . " and my favorite color is " . $color . ".</div>"; | |
// If the user selected Yellow as their color, print the yellow.jpg image | |
if ($color == "yellow") { | |
echo "<br /><img src='yellow.jpg' width='300' />"; | |
} | |
// add 1 to our counter | |
$count++; | |
} | |
// Setting up our second loop, which will print a string of text based on our number variable | |
$numcount = 1; | |
// This loop will be performed while our counter is less than or equal to $number (the number entered by the user) | |
while ($numcount <= $number) { | |
// Setting a second counter -- remember, this will be reset each time the loop is run | |
$tempnum = 1; | |
while ($tempnum <= $numcount) { | |
// Print some text | |
echo $numcount; | |
echo "&& "; | |
echo "///// "; | |
// add 1 to our temporary counter | |
$tempnum++; | |
} | |
// print another string of text | |
echo "* "; | |
// add 1 to our counter | |
$numcount++; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment