Rainbow Text

Rainbow Text

If the tag cloud is the mullet of the internet, then rainbow text is the camel toe of the net. Ghastly to look at, but you just can't take your eyes from it. There are many variations on how to produce rainbow text. This method employs a simple array of color values and applies them as the text is looped over. Great for your next emo site.


function rainbow($text)
/*** initialize the return string ***/
$ret '';

/*** an array of colors ***/
$colors = array(
/*** a counter ***/
$i 0;

/*** get the length of the text ***/
$textlength strlen($text);

/*** loop over the text ***/
/*** loop through the colors ***/
foreach($colors as $value)
            if (
$text[$i] != "")
$ret .= '<span style="color:#'.$value.';">'.$text[$i]."</span>";
/*** return the highlighted string ***/
return $ret;


Example Usage

/*** a line of text ***/
$text 'Charlie is choosing when choosing his cheeses and cheeses are a challenge when charlie arrives';

/*** highlight the text ***/
echo rainbow($text);


Charlie is choosing when choosing his cheeses and cheeses are a challenge when charlie arrives