/** * Return the length of the string without color codes. * * @param string $string the string to measure * @return string */ public static function length($string) { if (isset(self::$_string_cache[md5($string)]['decolorized'])) { $test_string = self::$_string_cache[md5($string)]['decolorized']; } else { $test_string = self::decolorize($string); } return safe_strlen($test_string); }
/** * An encoding-safe way of padding string length for display * * @param string $string The string to pad * @param int $length The length to pad it to * @return string */ function safe_str_pad($string, $length) { $cleaned_string = Colors::shouldColorize() ? Colors::decolorize($string) : $string; // Hebrew vowel characters $cleaned_string = preg_replace('#[\\x{591}-\\x{5C7}]+#u', '', $cleaned_string); if (function_exists('mb_strwidth') && function_exists('mb_detect_encoding')) { $real_length = mb_strwidth($cleaned_string, mb_detect_encoding($string)); } else { $real_length = safe_strlen($cleaned_string); } $diff = strlen($string) - $real_length; $length += $diff; return str_pad($string, $length); }