Interpolate a constant (not variable) into 'heredoc'

后端 未结 6 1707
梦谈多话
梦谈多话 2020-12-29 01:47

Consider:

The value of my_const is {my_const}.

MYECHO; ?>
6条回答
  •  情话喂你
    2020-12-29 02:18

    Use sprintf()

    define('my_const', 100);
    $string = <<< heredoc
          

    The value of my_const is %s.

    heredoc; $string = sprintf($string, my_const);

提交回复
热议问题