0, self::COLOR_GREEN => 10, self::COLOR_ORANGE => 208, self::COLOR_RED => 196, ]; public function paint($string, $textColor = null, $backgroundColor = null, $attribute = 0) { if (false === ($color = $this->parseColor($textColor))) { trigger_error('Invalid Color "' . $textColor . '"', E_USER_WARNING); return $string; } $result = self::START . ((int) $attribute) . ';38;5;' . $color . 'm'; if (null !== $backgroundColor) { if (false === ($color = $this->parseColor($backgroundColor))) { trigger_error('Invalid Background Color "' . $backgroundColor . '"', E_USER_WARNING); return $result . $string . self::END; } else { $result .= self::START . '48;5;' . $color . 'm'; } } $result .= $string . self::END; return $result; } protected function parseColor($color) { if (null === $color) { return false; } if (is_numeric($color)) { return (int) $color; } if (array_key_exists($color, $this->colors)) { return $this->colors[$color]; } return false; } }