Created
September 14, 2016 21:47
-
-
Save davidsword/9ed30f0cc4daddf9dd99fe885971c094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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