Skip to content

str_pad ​

php
string str_pad(string $lancuch, number $dlugosc [, string $wypelnienie [, number $typ]])

Returns $lancuch padded to $dlugosc characters using $wypelnienie. If $dlugosc is less than or equal to the length of $lancuch, the string is unchanged. If $wypelnienie is omitted, a space is used.

The fourth argument determines how the string is padded:

0 - pad on the left;

1 - pad on the right;

2 - pad on both sides.

If $typ is omitted, $lancuch is padded on the right.

Example:

php
$lancuch = "abc";
print(str_pad($lancuch, 5, "-"));

Result:

abc--