将PHP函数输出连接到类似变量的字符串

时间:2014-12-15 22:07:18

标签: php string string-concatenation

对于变量$x,我们可以通过多种方式将其连接到字符串,其中一个如下:

$x = "Hello";
echo "I say {$x} to all of you.";
// The output should be: I say Hello to all of you.

但是,如果我尝试使用某个功能执行此类操作,则会失败:

$x = "Hello";
echo "I say {strtolower($x)} to all of you.";
// The output should be: I say {strtolower(Hello)} to all of you.

如果存在与变量一样的同义词方式,我将不胜感激。换句话说,我不想拆分主字符串,我不想使用sprinf

1 个答案:

答案 0 :(得分:4)

您可以与.运算符连接:

echo "I say  " . strtolower($x) . " to all of you.";

或者只是:

echo "I say  ", strtolower($x), " to all of you.";