Re: heredoc question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux