Пример:
<?php $num = 5; $location = 'дереве'; $format = '%d обезьян сидят на %s'; echo sprintf($format, $num, $location); ?>