Generates rainbow text in two specters, Rainbow Colors and Pinks & Blues.
PHP Code:
if ($_POST['submit'] == "Generate Rainbow Text") {
//color arrays
$rainbow = array('#ff0000', '#ff3300', '#ff6600', '#ff9900', '#ffcc00',
'#ffff00', '#ccff00', '#99ff00', '#66ff00', '#33ff00', '#00ff00', '#00ff33',
'#00ff66', '#00ff99', '#00ffcc', '#00ffff', '#00ccff', '#0099ff', '#0066ff',
'#0033ff', '#0000ff', '#3300ff', '#6600ff', '#9900ff', '#cc00ff', '#ff00ff',
'#ff00cc', '#ff0099', '#ff0066', '#ff0033');
$pinkblue = array('#cc0000', '#ff6600', '#ff9900', '#99cc00', '#66cc00',
'#339900', '#339966', '#009999', '#0099cc', '#3399ff', '#3366ff',
'#3333ff', '#3300cc', '#6600cc', '#9900cc', '#cc00cc', '#ff00ff', '#ff00cc',
'#ff0099', '#ff0066', '#ff0033');
//get the message
$message = strip_tags($_POST['message']);
if (empty($message)) {
echo("Oops! You didn't type any text to rainbow-ify!");
}
else {
//decide which color array to use
if ($_POST['colorscheme'] == "rainbow") { $colorarr = $rainbow; }
else { $colorarr = $pinkblue; }
//split message into array of single letters
$messagearr = str_split($message);
$i = 0; //$i will keep count of which color in $colorarr we're up to
$max = count($colorarr); //the total number of colors in $colorarr
//loop through $messagearr
foreach ($messagearr as $letter) {
//if character isn't a space, assign color and add to $rainbowmsg:
if ($letter != " ") {
$rainbowmsg .= "<font color=\"".$colorarr[$i]."\">$letter</font>";
}
//else add a space to $rainbowmsg:
else { $rainbowmsg .= " "; }
//+1 to $i (so that the next loop uses the next color in $colorarr):
$i++;
//if we've reached the end of $colorarr, set $i to zero to start again:
if ($i == $max) { $i = 0; }
} //(end foreach loop)
//output the rainbow code:
echo("Your Rainbow Code:
<form action=\"\" method=\"post\">
<textarea rows=\"6\" cols=\"50\" name=\"rainbowcode\">$rainbowmsg
</textarea><br><br>
<input type=\"button\" value=\"Select All\"
onclick=\"this.form.rainbowcode.focus();
this.form.rainbowcode.select();\">
</form><br><br>");
} //end else (message not empty)
} //end if ($_POST)
echo '
<form action="" method="post">
<input type="radio" name="colorscheme" value="rainbow" checked="checked"> Rainbow Colors <br>
<input type="radio" name="colorscheme" value="pinkblue"> Pinks & Blues <br><br>
Enter some text to color: <br>
<textarea rows="6" cols="50" name="message"></textarea> <br><br>
<input type="submit" name="submit" value="Generate Rainbow Text">
</form>';
Comment