Re: heredoc question
| From: | Paul Novitski | Date: | Fri, 05 May 2006 14:53:34 +0000 |
| Subject: | Re: heredoc question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235650@lists.php.net to get a copy of this message | ||
At 07:40 AM 5/5/2006, Al wrote:
How can I include "place holders" for variables in a heredoc such that after the heredoc is declared, I can assign the variables?Al, Escape the $'s in your heredoc expression so that the variable names remain and aren't evaluated, then eval() the whole expression later:
$sString = <<< hdBodyClass
<body class="\$sBodyClass">
hdBodyClass;
This sets $sString equal to:
<body class="$sBodyClass">Then:
$sBodyClass = "contact";
eval("\$sHTML = '$sString';");
Evaluates as:
$sHTML = '<body class="contact">';As always, be careful not to include any external data in an eval() statement without careful sponging. Its presence in your script should be regarded as an Achilles heel and treated with special respect. Paul