← All built-ins / str_pad()

str_pad()

str_pad(...$args): string

Parameters

NameTypeDescription
$sstringinput string
$leninttarget length in bytes
$padstringpad string, default " " (space)optional

Return value

The string padded on the right with repeats of $pad up to $len bytes; unchanged when already longer.

Example

echo "[" . str_pad("7", 3, "0") . "]", "
";
echo "[" . str_pad("id:", 6) . "]", "
";
[700]
[id:   ]

See also

sprintf()substr()