52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
namespace App\Color;
|
|
|
|
class MinecraftColor {
|
|
|
|
private static $array = [
|
|
"&0" => "#333",
|
|
"&1" => "#2980b9",
|
|
"&2" => "#27ae60",
|
|
"&3" => "#01a3a4",
|
|
"&4" => "#c0392b",
|
|
"&5" => "#8e44ad",
|
|
"&6" => "#f39c12",
|
|
"&7" => "#95a5a6",
|
|
"&8" => "#7f8c8d",
|
|
"&9" => "#3498db",
|
|
"&a" => "#2ecc71",
|
|
"&b" => "#00d2d3",
|
|
"&c" => "#e74c3c",
|
|
"&d" => "#f368e0",
|
|
"&e" => "#f1c40f",
|
|
"&f" => "#bdc3c7"
|
|
];
|
|
|
|
private static $none = [
|
|
"&l", "&m", "&n", "&o", "&r",
|
|
];
|
|
|
|
public static function color($text) {
|
|
foreach(self::$array as $key => $value) {
|
|
$str = str_replace($key, $value, $text);
|
|
if($str !== $text) {
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public static function stripColor($text) {
|
|
foreach(self::$array as $key => $value) {
|
|
$text = str_replace($key, "", $text);
|
|
}
|
|
|
|
foreach(self::$none as $key) {
|
|
$text = str_replace($key, "", $text);
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
|
|
}
|