alrightgame
alrightgame

Reputation: 391

How to execute PHP code stored as a string?

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?

Upvotes: 0

Views: 1035

Answers (2)

Alex2php
Alex2php

Reputation: 11250

eval() 

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

Upvotes: 2

Christopher Armstrong
Christopher Armstrong

Reputation: 7953

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

Upvotes: 2

Related Questions