In a lot of cases you're better off using str_repeat if you want to use something like - it repeats the entire string.
Using str_repeat, I wrote a full string pad function that should closely mimic str_pad in every other way:
<?php
function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
$str = '';
$length = $pad_length - strlen($input);
if ($length > 0) { if ($pad_type == STR_PAD_RIGHT) { $str = $input.str_repeat($pad_string, $length);
} elseif ($pad_type == STR_PAD_BOTH) { $str = str_repeat($pad_string, floor($length/2));
$str .= $input;
$str .= str_repeat($pad_string, ceil($length/2));
} else { $str = str_repeat($pad_string, $length).$input;
}
} else { $str = $input;
}
return $str;
}
$pad_me = "Test String";
echo '|'.full_str_pad($pad_me, 20, ' ')."|\n";
echo '|'.full_str_pad($pad_me, 20, ' ', STR_PAD_RIGHT)."|\n";
echo '|'.full_str_pad($pad_me, 20, ' ', STR_PAD_BOTH)."|\n";
?>