Hi there

Is there a simple way to include constants inside a string when it's being given a value in Heredoc syntax, without assigning the constant's value to a variable beforehand?

Currently I do it like this:

<?

$constant = _CONSTANT;
$string = <<<EOD
<tag>blah blah blah {$constant} blah blah blah</tag>
EOD;

?>

I'd prefer to do something like...

<?

$string = <<<EOD
<tag>blah blah blah {_CONSTANT} blah blah blah</tag>
EOD;

?>

Thanks in advance for any advice!

    Next time I will have to take a closer look at php.net!

    Using the get_defined_constants() function I can get all the constants packed into one array. Then I only need to call the appropriate array value in the Heredoc-formatted string!

    eg.

    <?
    
    $const = get_defined_constants();
    
    $string = <<<EOD
    <tag>blah blah blah {$const['_CONSTANT']} blah blah blah</tag>
    EOD;
    
    ?>
    

    Pretty simple really.

      Write a Reply...