Question: 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?

Answer: 
<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](https://github.com/ieure/php_repl) and [phpsh](http://www.phpsh.org/).

The other part is the web interface for the interactive shell. For that part, I suggest you have a look at [repl.it](http://repl.it/), which provides this service for many languages (but sadly not PHP). [Here's a link](https://github.com/replit/repl.it) to it's source code.

With this combination, you should be able to complete cour project.
Look up 'eval()' and more importantly, why eval() and what you're trying to do is very difficult to achieve in a secure manner. Imaging for example the user who inputs:

```
echo file_get_contents('/etc/passwd');

```

You'll need quite a bit of work to make this secure, including watching and filtering all system calls being made from the eval'd process.

Cheers