如何将结果输出到字符串变量 - 这里出了什么问题?

Sam*_*Sam 2 php string variables

我在设置变量时遇到问题,然后给它翻译字符串的结果.我究竟做错了什么?

# usage: this translates some text into different language.
echo __('some text'); 

# make a variable and fill it with the outcome of the translated text
$title="echo __('translated content text')";
Run Code Online (Sandbox Code Playgroud)

第一行输出很好.第二行输出文字echo __('translated concent text').

更新

谢谢大家.很棒的答案.Gosh我一定是多么愚蠢,因此现在有点明智:)

$title = __('Colourful train rides');   # works
Run Code Online (Sandbox Code Playgroud)

现在正在尝试这些结局
ob_end_flush();
ob_end_clean();

Mar*_*ers 5

不要在函数调用周围包含引号,也不要调用echo:

$title = __('translated concent text');
Run Code Online (Sandbox Code Playgroud)

  • @Sam:我想你在这里不需要ob_*调用. (2认同)

ale*_*lex 5

第一行输出很好

听起来这个函数回声(如果它没有,它的名字会非常混乱).

您将需要使用输出缓冲区来捕获该输出.

ob_start();
__echo('translated concent text');
$title = ob_get_contents();
ob_end_clean(); // Thanks BoltClock
Run Code Online (Sandbox Code Playgroud)