(PHP 4, PHP 5, PHP 7, PHP 8)
sprintf — 返回格式化字符串
sprintf(string $format, mixed …$values): string
符號表示
S 以字串方式顯示
d以整數方式顯示
<?php
$num = 5;
$location = 'tree';
$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
?>
以上範例會输出:
There are 5 monkeys in the tree