Python 有一个名为 template strings 的功能。 .
>>> from string import Template
>>> s = Template('$who likes $what')
>>> s.substitute(who='tim', what='kung pao')
'tim likes kung pao'
我知道 PHP 允许你写:
"Hello $person"
并用 $person
代替,但模板可以在代码的各个部分重复使用?
最佳答案
你可以像这样使用模板字符串:
$name = "Maria";
$info["last_name"] = "Warner";
echo "Hello {$name} {$info["last_name"]}";
这将回显 Hello Maria Warner
。
关于php - PHP 有没有像 Python 的模板字符串那样的特性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683133/