Minecraft 使用某些特殊字符在其客户端上用颜色格式化字符串,我想从字符串中删除这些颜色代码,但也用适当的颜色格式化字符串。颜色代码的示例是:“§1”和“§6”您可以在此处查看完整列表:http: //www.minecraftwiki.net/wiki/Formatting_codes
以下是来自客户端的原始字符串示例:“§8here is the §6message of the §8day”我需要删除“§6”颜色代码并用适当颜色的 span 标签包围文本。这是我到目前为止所拥有的,我无法弄清楚。
我希望这个结果作为一个字符串:
<span style='color:#55555;'>here is the </span><span style='color:#FFAA00;'> message of the</span><span style='color:#55555;'> day</span>
我的功能:
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;
}
谢谢!