Help for this page

Select Code to Download


  1. 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);
    
  2. or download this
    $padded = $pad_char x ( $pad_len - length( $text ) ).$text;
    $padded = $text . $pad_char x ($pad_len - length($text));
    
  3. or download this
    substr($text, 0, 0)=$pad_charx($pad_len-length($text));
    $text .= $pad_char x ($pad_len - length($text));