Jump to content
Larry Ullman's Book Forums

Recommended Posts

This may be a rather odd question, but I'm looking for a way to run PHP code in a string as actual PHP code.

 

I have looked into the eval construct, but it has certain limitations that I need to be able to get around (like using return statements).

Also, using file_put_contents to first put the PHP in a file, and then running the code from the file is not an option.

 

Any ideas?

Thanks.

Link to comment
Share on other sites

eval() and writing it to a file are the only two options I can think of offhand. I would argue that if eval(), which is a last-resort, won't do it for you, that perhaps you should rethink what you're trying to do.

Link to comment
Share on other sites

(Edited out two paragraphs)

 

However, I can use basic HTML forms and insert info into DBs.

I was thinking that I could write some PHP code (with possibly HTML code as well), upload the code to a DB, and then when I want to execute the code, run it through eval or something.

 

So, yeah, the use case is admittedly very restrictive, and ultimately, I may not be able to do anything at all, but we'll see.

I want to at least try.

Link to comment
Share on other sites

The insertion of external media is also monitored.

 

Anyway, I was playing around with file_put_contents today, and had some luck.

It looks like it can be used under certan conditions.

Anyway, thanks.

 

I'll report back if/when I have any luck.

Link to comment
Share on other sites

 Share

×
×
  • Create New...