I would like to make something like tryruby.org. I take a line from the user (e.g., echo __FILE__
) and I want to execute it in PHP and return the output back to the client.
I tried to do exec('php -r ' . $command, $output)
, but $output
always contains the PHP help section.
How can I implement this feature?
http://tryruby.org seems have an interactive Ruby shell. That seems to be a good starting point.
Here are two projects that provide such a shell for PHP: php_repl and phpsh.
The other part is the web interface for the interactive shell. For that part, I suggest you have a look at repl.it, which provides this service for many languages (but sadly not PHP). Here's a link to it's source code.
With this combination, you should be able to complete cour project.
To make php -r
you have to have to put the code you want to execute between '
.. your code .. '
Example:
php -r ' $var = 34; print_r($var); '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With