Possible Duplicate:
Calling PHP functions within HEREDOC strings
I need to insert the results of functions into the middle of heredoc..
$r = func1();
$s = func2();
echo <<<EOT
line1
$r
$s
line3
EOT;
I am not sure if any better way to write it as I need to evaluate all the functions beforehand which make the code stupid.
Better if have something like..
echo <<<EOT
line1
{func1()}
{func2()}
line3
EOT;
Of course the above code does not work, but just want to show my idea…
No, there is no better way to do it.
Heredoc string syntax behaves much like double quote string syntax. You can’t put a function name as an expression inside of the double quoted string any more than you can a heredoc. So what you’re doing is fine and that’s how you should be doing it. The only time you can get interpolation inside of string syntax in PHP is if the value is a variable.
For example…
The above code would output