Michael Michael - 1 year ago 131
PHP Question

Interpolate constant (not variable) into heredoc?

define('my_const', 100);
echo <<<MYECHO
<p>The value of my_const is {my_const}.</p>

If i put a variable inside the braces it prints out. But not the constant. How can I do it?

Answer Source

Use sprintf()

define('my_const', 100);
$string = <<< heredoc
      <p>The value of my_const is %s.</p>

$string = sprintf($string, my_const);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download