Skip to content

Instantly share code, notes, and snippets.

@stephan-gh
Last active July 6, 2021 14:10
Show Gist options
  • Save stephan-gh/755e53aced83ab48513f to your computer and use it in GitHub Desktop.
Save stephan-gh/755e53aced83ab48513f to your computer and use it in GitHub Desktop.
Minecraft color parser for PHP
<?php
/*
* Minecraft Color Parser for PHP
* Copyright (c) 2013, Minecrell
* MIT License: http://opensource.org/licenses/MIT
*/
function parseMinecraftColors($string) {
$string = utf8_decode(htmlspecialchars($string, ENT_QUOTES, "UTF-8"));
$string = preg_replace('/\xA7([0-9a-f])/i', '<span class="mc-color mc-$1">', $string, -1, $count) . str_repeat("</span>", $count);
return utf8_encode(preg_replace('/\xA7([k-or])/i', '<span class="mc-$1">', $string, -1, $count) . str_repeat("</span>", $count));
}
/*
* Minecraft Color Parser for PHP
* Copyright (c) 2013, Minecrell
* MIT License: http://opensource.org/licenses/MIT
*/
/* Colors */
.mc-color.mc-0 { /* Black */ color: #000000; }
.mc-color.mc-1 { /* Dark Blue */ color: #0000AA; }
.mc-color.mc-2 { /* Dark Green */ color: #00AA00; }
.mc-color.mc-3 { /* Dark Aqua */ color: #00AAAA; }
.mc-color.mc-4 { /* Dark Red */ color: #AA0000; }
.mc-color.mc-5 { /* Purple */ color: #AA00AA; }
.mc-color.mc-6 { /* Gold */ color: #FFAA00; }
.mc-color.mc-7 { /* Gray */ color: #AAAAAA; }
.mc-color.mc-8 { /* Dark Gray */ color: #555555; }
.mc-color.mc-9 { /* Blue */ color: #5555FF; }
.mc-color.mc-a { /* Green */ color: #55FF55; }
.mc-color.mc-b { /* Aqua */ color: #55FFFF; }
.mc-color.mc-c { /* Red */ color: #FF5555; }
.mc-color.mc-d { /* Light Purple */ color: #FF55FF; }
.mc-color.mc-e { /* Yellow */ color: #FFFF55; }
.mc-color.mc-f { /* White */ color: #FFFFFF; }
/* Formatting */
.mc-color, .mc-r {
color: #ffffff;
font-weight: normal;
font-style: normal;
text-decoration: none;
}
.mc-k { /* TODO */ }
.mc-l { /* Bold */ font-weight: bold; }
.mc-m { /* Strikethrough */ text-decoration: line-through; }
.mc-n { /* Underline */ text-decoration: underline; }
.mc-o { /* Italic */ font-style: italic; }
/* Recommend Font: http://www.dafont.com/minecraftia.font */
@brokiem
Copy link

brokiem commented Jul 6, 2021

THANKS!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment