Exception or error:
I would like to execute a string as if it were PHP code.
An example would be:
$string='round(24.6,2)';
I would like to convert $string
to executable syntax. Is there a way to do this?
How to solve:
eval()
is the function you want. But: eval() is evil!
Answer:
You can use eval('round(24.6,2)')
, but this is usually frowned upon for multiple reasons. Why do you want to do this?