Mouner Mostafa Mouner Mostafa - 1 month ago 6x
MySQL Question

Run PHP code stored in a database

my table in database has value like that

<?php $s = 'my name is'; ?>

so when i call it in my page i have to use


but what am trying to do is calling the value as php code and want when type echo $s; to print my name is but now it's given my empty value see the code below to get what i mean

$b = '<?php $s = 'my name is';?>';
echo $b; //empty value


Sounds like you're talking about eval() - but I'd be wary of using it. If you do, be extremely careful.

"If eval() is the answer, you're almost certainly asking the wrong question." -Rasmus Lerdorf

You'd probably need to strip the <?php and ?> tags, and watch for double quotes surrounding variables you don't want to replace:

eval('$s = "my name is";');
echo $s;