Minecraft uses certain special characters to format strings with colors on their client, and I want to remove those color codes from the string but also format the string with the appropriate colors. An example of the color codes are: '§1' and '§6' You can see the full list here: http://www.minecraftwiki.net/wiki/Formatting_codes
Here is an example of my string raw from the client: "§8here is the §6message of the §8day" I need to remove the '§6' color code and surround the text with span tags with the appropriate color. Here is what I have so far, and I cannot figure this out.
I would want this result as a string:
<span style='color:#55555;'>here is the </span><span style='color:#FFAA00;'> message of the</span><span style='color:#55555;'> day</span>
My function:
function formatMOTD($motd) {
$result = array();
$previous;
$result = split("§1", $motd);
if (!empty($result)) {
foreach ($result as $value) {
$previous .= "<span style='color:#0000AA;'>" . substr($value, 1) . "</span>";
}
}
$result = split("§8", $motd);
if (!empty($result)) {
foreach ($result as $value) {
$previous .= "<span style='color:#55555;'>" . substr($value, 1) . "</span>";
}
}
$result = split("§6", $motd);
if (!empty($result)) {
foreach ($result as $value) {
$previous .= "<span style='color:#FFAA00;'>" . substr($value, 1) . "</span>";
}
}
$motd = $previous;
return $motd;
}
thanks!