Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Is It Possible To Put Into A Php Variable An HTML Piece Of Code Built From Plain Text And A Variable?

$
0
0

Hi All,

 

The heredoc syntax enables to put some text in a variable for future reuse. For example :

$my_var = <<<EOD
The colour is red.

EOD;

echo $my_var;

will result in "The colour is red". So far so good. Now let's assume the following:

$colour="red";
$my_var = <<<EOD
echo 'The colour is '.$colour;

EOD;

echo $my_var;

Unfortunately the result will be "echo 'The colour is '.red;".

 

In this situation, is there a way to tell php to just put "The colour is red" into the $my_var variable ? Or is there an alternative to heredoc ?

 

Thanks!

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles