/** * 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); }