str pad
Pad a string to a specified minimum length from another string
[...] = optional ... = your value
[var $... = ]str_pad $val=…;$pad_length=…;$pad_string=…[;$pad_type=…]
Notes
$pad_length must be specified it is the minimum total length of the string after padding
NOT the length of the padding
$pad_string is optional (defaults to spaces)
$pad_type is optional (defaults to right)
Options are
STR_PAD_RIGHT
STR_PAD_LEFT
STR_PAD_BOTH the padding is split evenly with any extra going to the right
Example code
<!--parser:xtscript-->
# Default pad_string is spaces
# Default pad_type is STR_PAD_RIGHT
var $input = foobar
var $pad_length = 12
var $output = call str_pad $val=$input;$pad_length=$pad_length
print input = $input<br />
print only 1 space will be visible in normal output<br />
print output = |$output|
print <pre>pre formatted output shows all the spaces\noutput = |$output|</pre>
# Padding with a string or character
var $pad_length = 15
var $pad_string = 12345
var $pad_type=STR_PAD_BOTH
var $output = call str_pad $val=$input; $pad_length=$pad_length; $pad_string=$pad_string; $pad_type=$pad_type
print input = $input<br />
print output = $output
<!--/parser:xtscript-->
Show in textareaExample output
Reloadinput = foobar
only 1 space will be visible in normal output
output = |foobar |
pre formatted output shows all the spaces
output = |foobar |
input = foobar
output = 1234foobar12345