- or download this
Left padding a string with blanks (no truncation:
$padded = sprintf("%${pad_len}s", $text);
...
$padded = sprintf("%0${pad_len}d", $num);
# Right padding a string with blanks using pack (will truncate):
$padded = pack("A$pad_len",$text);
- or download this
$padded = $pad_char x ( $pad_len - length( $text ) ).$text;
$padded = $text . $pad_char x ($pad_len - length($text));
- or download this
substr($text, 0, 0)=$pad_charx($pad_len-length($text));
$text .= $pad_char x ($pad_len - length($text));