1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| public function motd2Html($motd) { $colorCodeList = array( '§k' => '', '§l' => '<b>', '§m' => '<del>', '§n' => '<u>', '§o' => '<i>', '§r' => '<span style="color: #">', '§0' => '<span style="color: #000000">', '§1' => '<span style="color: #0000AA">', '§2' => '<span style="color: #00AA00">', '§3' => '<span style="color: #00AAAA">', '§4' => '<span style="color: #AA0000">', '§5' => '<span style="color: #AA00AA">', '§6' => '<span style="color: #FFAA00">', '§7' => '<span style="color: #AAAAAA">', '§8' => '<span style="color: #555555">', '§9' => '<span style="color: #5555FF">', '§a' => '<span style="color: #55FF55">', '§b' => '<span style="color: #55FFFF">', '§c' => '<span style="color: #FF5555">', '§d' => '<span style="color: #FF55FF">', '§e' => '<span style="color: #FFFF55">', '§f' => '<span style="color: #FFFFFF">', ); foreach ($colorCodeList as $color => $html){ $motd = str_replace($color, $html, $motd); } return closeHtmlTags($motd); }
public function closeHtmlTags($html) { @preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result); $openedtags = $result[1];
@preg_match_all('#</([a-z]+)>#iU', $html, $result); $closedtags = $result[1];
$len_opened = count((array) $openedtags); if (count((array) $closedtags) == $len_opened) { return $html; }
$openedtags = array_reverse($openedtags); for ($i = 0; $i < $len_opened; $i++) { if (!in_array($openedtags[$i], $closedtags)) { $html .= '</' . $openedtags[$i] . '>'; } else { unset($closedtags[array_search($openedtags[$i], $closedtags)]); } }
return $html; }
|