Yes its possible. Firstly Id get the words into an Array (getting rid of the spaces) randomize a set of predefined colours, now to do this you must loop the results that are in the Array and use <span> or however you wish to do it.
So here is one way to do it
<?php
$words = "My Funky String";
$wordList = explode(" ", $words);
$wordListSize = sizeof($wordList);
$colour = array("#ff0000", "#3333ff", "#ffff66", "#ff9966", "#009966");
$rand_keys = array_rand($colour, $wordListSize);
for ($i = 0; $i < $wordListSize; $i++)
$wordList[$i] = '<span style="color: '.$colour[$rand_keys[$i]].'">'.strtoupper($wordList[$i]).'</span>';
echo implode("", $wordList);
?>
Its not perfect but it does work.