- sprintf: documentation ( source)
<?php
$animal = 'dog';
$age = 4;
$sentance1 = 'The %s is %d years old';
$result1 = sprintf($sentance1, $animal, $age);
$sentance2 = 'Age: %d. Animal: %s';
$result2 = sprintf($sentance2, $age, $animal);
$sentance3 = 'Age: %2$d. Animal: %1$s';
$result3 = sprintf($sentance3, $animal, $age);
print($result1 . PHP_EOL);
print($result2 . PHP_EOL);
print($result3 . PHP_EOL);