In python, we can write COMMAND("%s.pdf"%param)
. How is it possible to do the same in PHP, e.g.
<iframe src="/example/%user_input.pdf"%param width="100%" height="100px"> </iframe>
In python, we can write COMMAND("%s.pdf"%param)
. How is it possible to do the same in PHP, e.g.
<iframe src="/example/%user_input.pdf"%param width="100%" height="100px"> </iframe>
You're looking for sprintf. See the PHP manual: https://www.php.net/manual/en/function.sprintf.php
`<?php
$num = 5;
$location = 'tree';
$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
?>`
I think the closest to Python 2 named parameter string formatting is strtr:
<?php
$params = [
'%user_input' => 'hello',
];
?>
<iframe src="<?php print strtr('/example/%user_input.pdf', $params); ?>" width="100%" height="100px"> </iframe>
This function does simple text replacements. It does not supoort variable type hints.