I have an simple question,
How to insert PHP code in PHP variable?
Example :
echo $value = "
bla
bla
<?php $q = "SELECT * FROM BLA BLA"; ?>
";
I have an simple question,
How to insert PHP code in PHP variable?
Example :
echo $value = "
bla
bla
<?php $q = "SELECT * FROM BLA BLA"; ?>
";
You can do it using eval()
$test = <<<END
<p> <?php
echo time();
?> </p>
END;
ob_start();
eval("?>$test");
$result = ob_get_clean();
Or an other example from w3s:
<?php
$string = "beautiful";
$time = "winter";
$str = 'This is a $string $time morning!';
echo $str. "<br>";
eval("\$str = \"$str\";");
echo $str;
?>
will print
This is a $string $time morning!
This is a beautiful winter morning!
But be very carefull when you use it, from the php page:
Caution The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.