← All built-ins / sprintf()

sprintf()

sprintf(...$args): string

Parameters

NameTypeDescription
$formatstringformat string with % placeholders
$...mixedvalues for the placeholders

Return value

The formatted string. Specifiers: %d %s %f %x %o %b %e %c, with width, precision and "-" left-align.

Example

echo sprintf("%s has %d points", "Ada", 42), "
";
echo sprintf("%.2f", 3.14159), "
";
echo sprintf("%05d", 42), "
";
Ada has 42 points
3.14
00042

See also

printf()vsprintf()number_format()