syntax – How to execute PHP code stored as a string?-ThrowExceptions

Exception or error:

I would like to execute a string as if it were PHP code.

An example would be:


I would like to convert $string to executable syntax. Is there a way to do this?

How to solve:

is the function you want. But: eval() is evil!


You can use eval('round(24.6,2)'), but this is usually frowned upon for multiple reasons. Why do you want to do this?

Leave a Reply

Your email address will not be published. Required fields are marked *