sabzh. there is a piece of code

echo <<< END

blah blah blah


(space before END specifically, because here the editor somehow clumsily handles without a space).

How inside blah blah insert function? variables are inserted there, and how to do functions?

  • $foo = Bar(); and variable to the right place! - Palmervan
  • Since no new variables can be changed or created inside HEREDOC, all values ​​that you want to calculate inside HEREDOC can be calculated before it, and the results of calculations can be used inside. In general, a direct answer to the question: no way. - ReinRaus
  • @alexlz, only for PHP >= 5.3.0 - Sergiks
  • @sergiks And where are the anonymous functions? The id function has an id name. The $ expr variable has the name $ expr. - alexlz

2 answers 2 speak ...

  function id($args) {return $args;} $expr = id; $a = <<<EOF 2 * 2 = {$expr(2 * 2) } Примерно. EOF; echo $a; 

Maybe in two moves?

 $tmpl = <<<END trololo function output here: %s int variable here: %d Ho ho ho END; printf( $tmpl, str_repeat('-',30), pow(3,4));