开发者

How to output the outcome into a string variable - what goes wrong here?

开发者 https://www.devze.com 2023-01-31 10:52 出处:网络
I\'m having trouble with setting a variable and then giving it the outcome of a translated string. What am I doing wrong?

I'm having trouble with setting a variable and then giving it the outcome of a translated string. What am I doing wrong?

# usage: this translates some text into different language.
echo __('some t开发者_StackOverflowext'); 

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

The first line outputs nicely. The second line output literaly echo __('translated concent text').

Update

Thanks all. great answers. Gosh how stupid i must ve been, therefore am a bit wiser now:)

$title = __('Colourful train rides');   # works

now experimenting with these endings

ob_end_flush();

ob_end_clean();


Don't include quotes around the function call and don't call echo:

$title = __('translated concent text');


The first line outputs nicely

It sounds like that function echoes (also, its name would be very confusing if it didn't).

You will need to use an output buffer to capture that output.

ob_start();
__echo('translated concent text');
$title = ob_get_contents();
ob_end_clean(); // Thanks BoltClock


You're wrapping the function call in quotes, so it's being outputted literally (instead of invoking the function). Take away the pair of quotes, and you'll have a result closer to what you want:

$title = __echo('translated concent text');

However, for this to work the __echo() function will have to return the string, not just echo it. If you want to catch the output, you'll have to use PHP's Output Buffering.

ob_start();
__echo('translated concent text');
$title = ob_get_contents();
ob_end_clean();
0

精彩评论

暂无评论...
验证码 换一张
取 消