Swat/SwatString.php
public static function pad(
        $input,
        $pad_length,
        $pad_string = ' ',
        $pad_type = STR_PAD_RIGHT
    ) {
        $output = '';
        $length = $pad_length - mb_strlen($input);

        if ($pad_string === null || mb_strlen($pad_string) === 0) {
            $pad_string = ' ';
        }

        if ($length > 0) {
            switch ($pad_type) {
                case STR_PAD_LEFT:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = mb_substr($padding, 0, $length) . $input;
                    break;

                case STR_PAD_BOTH:
                    $left_length = floor($length / 2);
                    $right_length = ceil($length / 2);
                    $padding = str_repeat(
                        $pad_string,
                        ceil($right_length / mb_strlen($pad_string))
                    );
                    $output =
                        mb_substr($padding, 0, $left_length) .
                        $input .
                        mb_substr($padding, 0, $right_length);

                    break;

                case STR_PAD_RIGHT:
                default:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = $input . mb_substr($padding, 0, $length);
            }
        } else {
            $output = $input;
        }
        return $output;
    }
public static function pad(
        $input,
        $pad_length,
        $pad_string = ' ',
        $pad_type = STR_PAD_RIGHT
    ) {
        $output = '';
        $length = $pad_length - mb_strlen($input);

        if ($pad_string === null || mb_strlen($pad_string) === 0) {
            $pad_string = ' ';
        }

        if ($length > 0) {
            switch ($pad_type) {
                case STR_PAD_LEFT:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = mb_substr($padding, 0, $length) . $input;
                    break;

                case STR_PAD_BOTH:
                    $left_length = floor($length / 2);
                    $right_length = ceil($length / 2);
                    $padding = str_repeat(
                        $pad_string,
                        ceil($right_length / mb_strlen($pad_string))
                    );
                    $output =
                        mb_substr($padding, 0, $left_length) .
                        $input .
                        mb_substr($padding, 0, $right_length);

                    break;

                case STR_PAD_RIGHT:
                default:
                    $padding = str_repeat(
                        $pad_string,
                        ceil($length / mb_strlen($pad_string))
                    );
                    $output = $input . mb_substr($padding, 0, $length);
            }
        } else {
            $output = $input;
        }
        return $output;
    }
public static function pad ( $ input , $ pad_length , $ pad_string = ' ' , $ pad_type = STR_PAD_RIGHT ) { $ output = '' ; $ length = $ pad_length - mb_strlen ( $ input ) ; if ( $ pad_string === null || mb_strlen ( $ pad_string ) === 0 ) { $ pad_string = ' ' ; } if ( $ length > 0 ) { switch ( $ pad_type ) { case STR_PAD_LEFT : $ padding = str_repeat ( $ pad_string , ceil ( $ length / mb_strlen ( $ pad_string ) ) ) ; $ output = mb_substr ( $ padding , 0 , $ length ) . $ input ; break ; case STR_PAD_BOTH : $ left_length = floor ( $ length / 2 ) ; $ right_length = ceil ( $ length / 2 ) ; $ padding = str_repeat ( $ pad_string , ceil ( $ right_length / mb_strlen ( $ pad_string ) ) ) ; $ output = mb_substr ( $ padding , 0 , $ left_length ) . $ input . mb_substr ( $ padding , 0 , $ right_length ) ; break ; case STR_PAD_RIGHT : default : $ padding = str_repeat ( $ pad_string , ceil ( $ length / mb_strlen ( $ pad_string ) ) ) ; $ output = $ input . mb_substr ( $ padding , 0 , $ length ) ; } } else { $ output = $ input ; } return $ output ; }
Pads a string in a UTF-8 safe way.

@param string $input the string to pad.
@param int $pad_length length in characters to pad to.
@param string $pad_string string to use for padding.
@param int $pad_type type of padding to use: <code>STR_PAD_LEFT</code>,
<code>STR_PAD_RIGHT</code>, or
<code>STR_PAD_BOTH</code>.

@return string the padded string.
Pads a string in a UTF - 8 safe way .