Insert PHP Code In PHP Variable -
i have simple question,
how insert php code in php variable?
example :
echo $value = " bla bla <?php $q = "select * bla bla"; ?> ";
you can using eval()
$test = <<<end <p> <?php echo time(); ?> </p> end; ob_start(); eval("?>$test"); $result = ob_get_clean();
or other example w3s:
<?php $string = "beautiful"; $time = "winter"; $str = 'this $string $time morning!'; echo $str. "<br>"; eval("\$str = \"$str\";"); echo $str; ?>
will print
this $string $time morning!
this beautiful winter morning!
but carefull when use it, php page:
caution eval() language construct dangerous because allows execution of arbitrary php code. use discouraged. if have verified there no other option use construct, pay special attention not pass user provided data without validating beforehand.
Comments
Post a Comment