Skip to content

Instantly share code, notes, and snippets.

@davidsword
Created September 14, 2016 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsword/9ed30f0cc4daddf9dd99fe885971c094 to your computer and use it in GitHub Desktop.
Save davidsword/9ed30f0cc4daddf9dd99fe885971c094 to your computer and use it in GitHub Desktop.
<?
function color_me($phrase, $color = 2, $class = 'red') {
$words = explode(' ', $phrase);
$reconstructed_phrase = '<span class="'.$class.'">';
$hasclosed = false;
foreach ($words as $k => $word) {
if ($k == $color) {
$reconstructed_phrase .= "</span>";
$hasclosed = true;
}
$reconstructed_phrase .= $word." ";
}
if (!$hasclosed)
$reconstructed_phrase .= "</span>";
return $reconstructed_phrase;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment