HartleySan Posted October 3, 2012 Share Posted October 3, 2012 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 More sharing options...
Larry Posted October 3, 2012 Share Posted October 3, 2012 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 More sharing options...
HartleySan Posted October 3, 2012 Author Share Posted October 3, 2012 That's a fair enough thing to say. I was just hoping that there was something I was missing or that someone had something really creative up their sleeve. I'll mess around with eval and see if I can get it to suit my needs. Thanks, Larry. Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 3, 2012 Share Posted October 3, 2012 What's the use case here? Link to comment Share on other sites More sharing options...
HartleySan Posted October 4, 2012 Author Share Posted October 4, 2012 (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 More sharing options...
Antonio Conte Posted October 4, 2012 Share Posted October 4, 2012 Thought of using Xampp on a memory stick? Link to comment Share on other sites More sharing options...
HartleySan Posted October 4, 2012 Author Share Posted October 4, 2012 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 More sharing options...
Recommended Posts