diff --git a/file/lib/util/ChatUtil.class.php b/file/lib/util/ChatUtil.class.php index 7543a78..d45f58f 100644 --- a/file/lib/util/ChatUtil.class.php +++ b/file/lib/util/ChatUtil.class.php @@ -30,7 +30,7 @@ class ChatUtil { * @returen string */ public static function gradient($string, $start, $end) { - $string = str_split($string); + $string = self::str_split($string); $r = (int) ((($start >> 16 & 255) - ($end >> 16 & 255)) / (count($string) - 1)); $g = (int) ((($start >> 8 & 255) - ($end >> 8 & 255)) / (count($string) - 1)); $b = (int) ((($start & 255) - ($end & 255)) / (count($string) - 1)); @@ -43,6 +43,22 @@ public static function gradient($string, $start, $end) { return $result; } + /** + * Splits a string into smaller chunks. + * UTF-8 safe version of str_split(). + * + * @param string $string + * @param integer $length + * @return array + */ + public static function str_split($string, $length = 1) { + $result = array(); + for ($i = 0, $max = StringUtil::length($string); $i < $max; $i += $length) { + $result[] = StringUtil::substring($string, $i, $length); + } + return $result; + } + /** * Creates an interval out of a string with modifiers. * Modifiers may be mixed. Valid modifiers are: _s_econd, _h_our, _d_ay, _w_week, _m_onth, _y_ear