1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Adding UTF-8 save version of str_split

This commit is contained in:
Tim Düsterhus 2011-12-13 18:15:30 +01:00
parent f6d8273d86
commit c5821e543b

View File

@ -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<string>
*/
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