Rainbow Text
Author : fkroerank
I figured that it could be done using an array of hex codes and heres what I've come up with
| PHP Example : | | <?php
function rainbow($text) {
$colors = array('ff00ff','ff00cc','ff0099','ff0066','ff0033','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');
$i = 0;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
if ($text[$i] != "") echo "<font color=\"#".$value."\">".$text[$i]."</font>";
$i++;
}
}
}
?>
|
Usage Example:
| PHP Example : | | <?php
function rainbow($text) {
$colors = array('ff00ff','ff00cc','ff0099','ff0066','ff0033','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');
$i = 0;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
if ($text[$i] != "") echo "<font color=\"#".$value."\">".$text[$i]."</font>";
$i++;
}
}
}
?>
<html>
<head>
<title>Rainbow text</title>
</head>
<body>
<?php
$this_text = "this text would become rainbow text";
rainbow($this_text);
?>
</body>
</html>
| |