Jump to content

Understanding how to use eval

Recommended Posts

How can I save a little PHP code to $Tom, and then evaluate $Tom and save that to a variable as attempted below:?

$Tom = "echo 'blah'"eval($Tom);

When I try and use eval here, I get the following error:

Parse error: syntax error, unexpected $end, expecting ',' or ';'


Worse still, I want to save the result of eval to an array element.


as for saving the value to an array, I tried

$bob = eval($Tom);and array_push($myarray, $varone, "'".eval($Tom)."'") 

Didn't work.

I am very frustrated with eval.

How can I do what I am trying to do?

That is, save the result of eval to an array element?


I did a search on eval, and got a lot of suggestions and saw lots of requests for a replacement function, but the suggestions were what I have seen before, and did not know how to apply, and the requests for a replacement function went unanswered.



You guys are great.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...