Jim Maguire
Jim Maguire

Reputation: 1030

Get PHP to run code contained in a string

You have a string, which contains a snippet of PHP code:

$run_me = "echo ('Hello World!!');";

How can you get PHP to run the code, contained in $run_me?

You can't do:

include ($run_me);

That would include the path $run_me, so what's the solution?

Upvotes: 0

Views: 61

Answers (1)

Ramsay Smith
Ramsay Smith

Reputation: 1108

One way is to use eval(). This will execute the string you enter as PHP code.

Upvotes: 3

Related Questions