- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/text/utfsafestring.php
- Класс: BitrixMainTextUtfSafeString
- Вызов: UtfSafeString::pad
static function pad($string, $padLen, $padStr = ' ', $padType = STR_PAD_RIGHT)
{
$strLength = mb_strlen($string);
$padStrLength = mb_strlen($padStr);
if (!$strLength && ($padType == STR_PAD_RIGHT || $padType == STR_PAD_LEFT))
{
$strLength = 1; // @debug
}
if (!$padLen || !$padStrLength || $padLen <= $strLength)
{
return $string;
}
$result = null;
$repeat = ceil(($padLen - $strLength) / $padStrLength);
if ($padType == STR_PAD_RIGHT)
{
$result = $string . str_repeat($padStr, $repeat);
$result = mb_substr($result, 0, $padLen);
}
else if ($padType == STR_PAD_LEFT)
{
$result = str_repeat($padStr, $repeat) . $string;
$result = mb_substr($result, -$padLen);
}
else if ($padType == STR_PAD_BOTH)
{
$length = ($padLen - $strLength) / 2;
$repeat = ceil($length / $padStrLength);
$result = mb_substr(str_repeat($padStr, $repeat), 0, floor($length))
.$string
.mb_substr(str_repeat($padStr, $repeat), 0, ceil($length));
}
return $result;
}